How to Back Up Configuration Files and Server State

Beyond databases and application files, a complete backup strategy should capture your server's configuration — the settings that would take significant time to reconstruct from memory after a rebuild.

Why Configuration Backups Matter

Even with data restored, a rebuilt server without its original configuration means manually reconfiguring the firewall, web server, cron jobs, and every other customization — a slow, error-prone process during an already stressful recovery.

What to Back Up

CategoryTypical Locations
Web server config/etc/nginx/, /etc/apache2/
Firewall rules/etc/ufw/, or exported iptables rules
SSH configuration/etc/ssh/sshd_config
Cron jobs/etc/cron.d/, individual user crontabs
SSL certificates/etc/letsencrypt/
Application environment files.env files (handle securely due to secrets)
systemd service files/etc/systemd/system/
Fail2Ban configuration/etc/fail2ban/jail.local

Creating a Configuration Backup Script

sudo nano /usr/local/bin/backup-config.sh
#!/bin/bash
TIMESTAMP=$(date +%F)
BACKUP_DIR="/var/backups/config"
mkdir -p "$BACKUP_DIR"

tar czf "$BACKUP_DIR/config-$TIMESTAMP.tar.gz" \
  /etc/nginx \
  /etc/ssh/sshd_config \
  /etc/ufw \
  /etc/fail2ban/jail.local \
  /etc/cron.d \
  /etc/systemd/system \
  /etc/letsencrypt \
  2>/dev/null

find "$BACKUP_DIR" -type f -mtime +30 -delete
sudo chmod +x /usr/local/bin/backup-config.sh

Exporting Package Lists (For Reconstructing Installed Software)

dpkg --get-selections > "$BACKUP_DIR/installed-packages-$(date +%F).txt"

Restoring from this list on a new server:

sudo dpkg --set-selections < installed-packages.txt
sudo apt-get dselect-upgrade

Exporting Crontabs for All Users

for user in $(cut -f1 -d: /etc/passwd); do
    crontab -l -u "$user" 2>/dev/null > "$BACKUP_DIR/crontab-$user.txt"
done

Scheduling Configuration Backups

sudo crontab -e
0 1 * * 0 /usr/local/bin/backup-config.sh

Weekly is usually sufficient for configuration, since it changes far less frequently than application data.

Storing Configuration Backups Off-Site

Include the config backup directory in your regular off-site sync/upload routine alongside database and file backups — see How to Back Up to Object Storage (S3-Compatible).

Consider Infrastructure as Code Instead

For frequently rebuilt or scaled infrastructure, consider managing configuration through version-controlled provisioning scripts or configuration management tools rather than relying solely on point-in-time config backups — this makes "configuration" itself a reproducible, auditable artifact rather than a snapshot to restore.

Handling Secrets Securely in Configuration Backups

Configuration backups often contain sensitive values (database passwords in config files, API keys). Encrypt these backups specifically:

gpg --symmetric --cipher-algo AES256 config-backup.tar.gz

Common Errors

Restored configuration references paths/users that don't exist on the new server — verify the new server's setup matches assumptions in the old configuration (usernames, directory structure) before applying wholesale.

Best Practices

  • Back up configuration alongside data, not as an afterthought
  • Encrypt configuration backups containing secrets
  • Test restoring configuration onto a fresh test server periodically

Related Articles

  • How to Create a Disaster Recovery Plan for Your VPS
  • How to Manage Environment Variables and Secrets on a VPS
  • Backup Strategy 101: The 3-2-1 Rule Explained
  • configuration backup, server state backup, infrastructure backup, disaster recovery
  • 0 Корисниците го најдоа ова како корисно
Дали Ви помогна овој одговор?

Понудени резултати

Backup Strategy 101: The 3-2-1 Rule Explained

Before diving into specific backup tools, it's worth understanding the industry-standard...

How to Back Up to Object Storage (S3-Compatible)

S3-compatible object storage provides durable, cost-effective off-site backup storage —...

How to Test and Verify Your Backups Actually Work

A backup that has never been restored is not a verified backup — it's an assumption. This...

How to Create a Disaster Recovery Plan for Your VPS

A disaster recovery (DR) plan is a documented, tested procedure for restoring service after a...

How to Use VPS Provider Snapshots Effectively

Most VPS providers offer a snapshot feature — a point-in-time image of your entire server....