Backup Configuration
Learning Focus
By the end of this lesson you will know exactly what to backup, how to create reliable backups, and how to restore them after a failed change or upgrade.
What to Backup
| Item | Path | Why |
|---|---|---|
| Server config | /usr/local/lsws/conf/ | Main server and vhost configuration |
| Virtual host configs | /usr/local/lsws/conf/vhosts/ | Per-site settings |
| SSL certificates | /etc/ssl/private/, /etc/ssl/certs/ | Certificate and key files |
| WebAdmin password | /usr/local/lsws/admin/conf/ | Admin credentials |
| PHP config | /usr/local/lsws/lsphp*/etc/php/*/lsphp/php.ini | Custom PHP settings |
| Application files | /var/www/ | Site code, uploads, themes |
| Rewrite rules | .htaccess files in doc roots | URL routing rules |
Quick Backup Script
backup-ols.sh
#!/bin/bash
# OpenLiteSpeed configuration backup script
BACKUP_DIR="/root/backups/ols-$(date +%Y%m%d-%H%M%S)"
mkdir -p "$BACKUP_DIR"
# 1) Server configuration
sudo cp -r /usr/local/lsws/conf "$BACKUP_DIR/conf"
# 2) Admin configuration
sudo cp -r /usr/local/lsws/admin/conf "$BACKUP_DIR/admin-conf"
# 3) SSL certificates
sudo cp -r /etc/ssl/private "$BACKUP_DIR/ssl-private" 2>/dev/null
sudo cp -r /etc/ssl/certs "$BACKUP_DIR/ssl-certs" 2>/dev/null
# 4) PHP configuration
for phpdir in /usr/local/lsws/lsphp*/etc; do
if [ -d "$phpdir" ]; then
phpver=$(echo "$phpdir" | grep -oP 'lsphp\K[0-9]+')
sudo cp -r "$phpdir" "$BACKUP_DIR/php$phpver-etc"
fi
done
# 5) Create a compressed archive
tar -czf "$BACKUP_DIR.tar.gz" -C "$(dirname $BACKUP_DIR)" "$(basename $BACKUP_DIR)"
rm -rf "$BACKUP_DIR"
echo "Backup saved to: $BACKUP_DIR.tar.gz"
echo "Backup size: $(du -h $BACKUP_DIR.tar.gz | cut -f1)"
Make It Executable
chmod +x backup-ols.sh
sudo ./backup-ols.sh
Restore Process
# 1) Extract the backup
tar -xzf /root/backups/ols-20260310-143000.tar.gz -C /tmp/
# 2) Stop the server
sudo systemctl stop lsws
# 3) Restore config files
sudo cp -r /tmp/ols-20260310-143000/conf/* /usr/local/lsws/conf/
# 4) Restore SSL if needed
sudo cp -r /tmp/ols-20260310-143000/ssl-private/* /etc/ssl/private/
sudo chmod 600 /etc/ssl/private/*
# 5) Start the server
sudo systemctl start lsws
# 6) Verify
tail -20 /usr/local/lsws/logs/error.log
curl -I http://localhost
Backup Schedule Recommendation
| Frequency | What to Backup | When |
|---|---|---|
| Before every change | Config directory | Before any WebAdmin or file edit |
| Before upgrades | Config + SSL + PHP | Before apt upgrade or dnf upgrade |
| Weekly | Full backup script | Automated via cron |
| Monthly | Off-site copy | Copy to remote storage or backup service |
Automate with Cron
# Run backup every Sunday at 2 AM
echo "0 2 * * 0 root /root/scripts/backup-ols.sh" | sudo tee /etc/cron.d/ols-backup
warning
Backups only protect you if they are tested. Periodically verify you can restore from a backup by doing a test restore on a non-production server.
Key Takeaways
- Always backup before changes — config, SSL, and PHP settings.
- Use a scripted backup so it is repeatable and consistent.
- Keep backups off the server for disaster recovery.
- Test your restore process — an untested backup is not a real backup.