A Linux server backup is more than a copy of /home. To bring a server back after a disk failure, a hacked system or a deleted VM, you need the right data, the configuration that runs it, a copy that lives somewhere else, and a recovery procedure you have actually tried. This guide explains what to back up on a Linux server, which methods and tools to use, and how to plan a full recovery.

The problem: servers are rebuilt from memory

When a Linux server dies without a proper backup, the team tries to rebuild it from memory: which packages were installed, how Nginx was configured, where the application kept its uploads, which cron jobs ran at night. Something is always missing. Recovery stretches from hours to days, and some data, such as the last database changes or files uploaded by customers, is simply gone.

The consequence for the business is downtime, lost revenue and sometimes a data protection incident to report. A planned Linux server backup turns that rebuild into a restore.

What to back up on a Linux server

Path or itemWhy it matters
/etcSystem and service configuration: web server, SSH, firewall, users, mounts
/home, /rootUser files, SSH keys, scripts kept in home directories
/srv, /var/www, /optApplications and websites, depending on your layout
/var/lib/<app>Application state (but see databases below)
/usr/localSoftware and scripts installed outside the package manager
/var/spool/cron and /etc/cron.*Scheduled jobs
Package listTo reinstall the same software quickly (dpkg --get-selections or rpm -qa)
Database dumpsConsistent copies of MySQL, MariaDB, PostgreSQL and others
Docker volumes and Compose filesContainer data and the definition of the stack
TLS certificates and keysOften under /etc/letsencrypt; included with /etc, but must be encrypted in the backup

Do not back up /proc, /sys, /dev, /run and /tmp: they are virtual or temporary. Caches such as /var/cache can be excluded to save space.

Databases need special handling

Copying the files under /var/lib/mysql or /var/lib/postgresql while the database is running produces copies that may not start. Dump the databases first, to a directory included in the file backup, using mysqldump --single-transaction, mariadb-dump or pg_dump. See the database backup guide and automatic MySQL backup.

Three methods of Linux server backup

MethodHowRestoreBest for
File-levelCopies selected directories (restic, Borg, rsync, tar)Single files fast; full server requires reinstall plus restoreMost servers, especially with configuration management
Image-level (bare metal)Copies the whole disk or system (Relax-and-Recover, Clonezilla, hypervisor backups)Entire machine at once, including partitions and boot loaderServers that are hard to rebuild
SnapshotsLVM, ZFS, Btrfs or cloud provider snapshotsVery fast rollback on the same storageShort-term protection before changes; not a backup on their own

A common and robust combination is a daily file-level backup offsite plus snapshots for fast rollbacks. For virtual machines on Proxmox VE, back up the whole VM at the hypervisor level as well; see the Proxmox VE backup guide.

Choosing a tool

  • restic: encrypted, deduplicated, incremental, supports S3, SFTP and many backends. A single binary.
  • BorgBackup: encrypted, deduplicated, very efficient compression, usually over SSH to a Borg server.
  • rsync: fast synchronization, but no encryption or version history unless combined with hard-link snapshots.
  • tar: simple archives, useful for occasional copies, inefficient for daily backups.
  • Relax-and-Recover (ReaR): creates a rescue image to restore a whole system onto new hardware, combined with a file backup.

A complete restic setup with scheduling, retention and alerts is described in automatic Linux backup.

A minimal backup for one server

# 1. Dump databases (example: MySQL) into the backup area
mysqldump --defaults-extra-file=/root/.my-backup.cnf --single-transaction \
  --routines --triggers --events --all-databases | gzip > /var/backups/mysql-all.sql.gz

# 2. Save the package list
dpkg --get-selections > /var/backups/packages.txt     # Debian/Ubuntu
# rpm -qa | sort > /var/backups/packages.txt        # RHEL family

# 3. Encrypted, deduplicated backup offsite
restic backup /etc /home /root /srv /var/www /usr/local /var/backups /var/spool/cron \
  --exclude-caches

# 4. Retention
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --prune

Where to store the backup

Follow the 3-2-1-1-0 rule. A second disk in the same server protects only against disk failure. A backup server in the same rack protects against more, but not against fire, flood or an attacker with access to your network. At least one copy must be offsite, encrypted, and preferably immutable for a period (object lock) so ransomware on the server cannot delete it. Read about offsite data center backup to compare options.

Plan the full recovery

Write the procedure before you need it:

  1. Provision a new server or VM with the same distribution and version.
  2. Install the backup tool and connect to the repository (you need the password stored outside the server).
  3. Reinstall packages from the saved list: dpkg --set-selections < packages.txt && apt-get dselect-upgrade.
  4. Restore /etc carefully (network settings, disk UUIDs in /etc/fstab and host keys may need adjustment), then the application directories.
  5. Restore databases from the dumps.
  6. Update DNS, check certificates, test the application, and only then reopen traffic.

Run this procedure on a test machine at least twice a year and measure the time it takes. That number is your real recovery time; compare it with your RTO.

Common Linux server backup mistakes

  • Backing up only data and not configuration, or the reverse.
  • Copying live database files instead of dumps.
  • Keeping the backup encryption password only on the server.
  • Treating snapshots or RAID as backups.
  • Never testing a full restore.

Backnix is being built to back up Linux servers with a lightweight agent, client-side encryption and offsite storage, with file and full-system recovery. See the server backup page for the current status and the plans and prices.

References

Topics: Disaster recoveryLinuxresticServer backup