How to Back Up an Ubuntu Server: rsync, Borg, Restic, and Snapshots

Ubuntu server backup process copying files and databases to storage
Ubuntu server backup process copying files and databases to storage

Why a Proper Ubuntu Backup Strategy Matters

Hardware failures, botched package upgrades, accidental rm commands, and ransomware can wipe out a production host in seconds. Whether you run Ubuntu 24.04 LTS or Ubuntu 26.04 LTS, a tested Ubuntu backup plan lets you restore configurations, files, and databases cleanly instead of rebuilding from memory.

This guide covers the 3-2-1-1-0 rule, what to include and exclude, practical commands for rsync, tar, BorgBackup, and Restic, how Timeshift and Déjà Dup fit in, consistent database dumps, systemd timers, ransomware-proof offsite storage, and restore testing.

Key Facts: Ubuntu Server Backup at a Glance

  • LTS versions covered: Ubuntu 24.04 LTS (Noble Numbat) and Ubuntu 26.04 LTS (Resolute Raccoon, released April 2026 and supported until April 2031).
  • Strategy: 3-2-1-1-0 rule (3 copies, 2 media types, 1 offsite, 1 immutable/offline, 0 unverified restores).
  • Primary tools: BorgBackup (1.2.8 in 24.04 / 1.4.4 in 26.04) or Restic (0.16.4 in 24.04 / 0.18.1 in 26.04) for encrypted deduplication; rsync and tar for mirrors and archives.
  • Desktop tools note: Déjà Dup is for desktop user files; Timeshift creates local OS rollback snapshots (skipping /home by default) and is not an offsite backup.
  • Databases: dump MySQL/MariaDB or PostgreSQL logically before copying files.
  • Automation: use systemd timers for journalctl logs and missed-run catch-up.

Follow the 3-2-1 (and 3-2-1-1-0) Backup Rule

CISA’s backup guidance recommends keeping at least 3 copies of data on 2 different storage media, with 1 copy offsite. To defend against ransomware and compromised admin keys, extend this to 3-2-1-1-0: add 1 immutable or offline copy that the live server cannot delete, and maintain 0 errors via automated checks and restore drills.

Ubuntu backup architecture diagram showing the 3-2-1-1-0 rule across live Ubuntu 24.04 and 26.04 LTS server, local encrypted Borg or Restic repo, immutable offsite storage, and restore verification
The 3-2-1-1-0 Ubuntu backup architecture balancing fast local recovery and immutable offsite protection.

What to Back Up on an Ubuntu Server

Skip virtual kernel filesystems and focus on configuration, application state, and recovery manifests:

  • Configs & certs: /etc/ (Nginx, Apache, SSH, UFW/nftables, systemd units in /etc/systemd/system/, and /etc/letsencrypt/).
  • App data & users: /var/www/, /srv/, container volumes, and /home/.
  • Database dumps: scheduled exports in /var/backups/db/.
  • Package list: run apt-mark showmanual > /var/backups/apt-manual.txt so you can reinstall software on a clean Ubuntu image.

For full-filesystem mirrors, exclude /dev/*, /proc/*, /sys/*, /tmp/*, /run/*, /mnt/*, /media/*, /lost+found, and /var/cache/*.

Choosing the Right Ubuntu Backup Tool

Match the tool to your recovery goal: quick directory mirrors, portable archives, or encrypted deduplicated offsite repositories.

Ubuntu backup tools comparison matrix for BorgBackup, Restic, rsync, tar, and Timeshift snapshots showing encryption, deduplication, offsite support, and best server use cases
Comparison of core Ubuntu server backup tools across encryption, deduplication, and offsite support.

1. Incremental Mirroring with rsync

rsync mirrors files quickly while preserving permissions, ACLs, and extended attributes. Store exclusions in a file so scripts work identically under cron, systemd, and interactive shells:

sudo rsync -aAXHv --delete --exclude-from=/etc/backup-exclude.txt / /mnt/backup/ubuntu-mirror/
sudo rsync -aAXHz --delete /etc /var/www /var/backups/db backup@198.51.100.10:/srv/backups/web01/

Remember that /etc/ copies directory contents whereas /etc copies the folder itself, and always dry-run (-n) before enabling --delete. For multi-day hardlink snapshots over rsync, see Ubuntu’s rsnapshot guide. Note that rsync encrypts only in transit over SSH, not at rest.

2. Portable Archives with tar

tar is ideal for quick snapshots of /etc before config changes. Keep archives outside web roots and encrypt with gpg --symmetric --cipher-algo AES256 before uploading offsite:

sudo tar --acls --xattrs -czpf /var/backups/etc-$(date +%F).tar.gz /etc
tar -tzvf /var/backups/etc-$(date +%F).tar.gz | head

3. Encrypted SSH Backups with BorgBackup

BorgBackup provides chunk-level deduplication, compression, and client-side encryption. Ubuntu 24.04 ships borgbackup 1.2.8 and Ubuntu 26.04 ships 1.4.4 (26.04 also includes borgbackup2 as a 2.0.0b20 beta, so use stable borgbackup 1.x in production):

sudo apt update && sudo apt install -y borgbackup
export BORG_PASSPHRASE="strong-generated-passphrase"

borg init --encryption=repokey-blake2 ssh://borg@backup.example.com:22/srv/borg/web01
borg key export ssh://borg@backup.example.com:22/srv/borg/web01 /root/borg-key.txt

borg create --stats --compression zstd,6 \
  ssh://borg@backup.example.com:22/srv/borg/web01::"{hostname}-{now:%Y-%m-%d}" \
  /etc /var/www /home /var/backups/db

borg prune --list --keep-daily=7 --keep-weekly=4 --keep-monthly=6 \
  ssh://borg@backup.example.com:22/srv/borg/web01
borg compact ssh://borg@backup.example.com:22/srv/borg/web01

4. Encrypted S3 & Cloud Backups with Restic

Restic (0.16.4 in Ubuntu 24.04; 0.18.1 in Ubuntu 26.04) encrypts and deduplicates data natively to S3-compatible buckets, Backblaze B2, SFTP, or rclone:

sudo apt update && sudo apt install -y restic
export RESTIC_REPOSITORY="s3:s3.us-east-1.amazonaws.com/my-ubuntu-backups/web01"
export RESTIC_PASSWORD_FILE="/root/.restic-pass"

restic init
restic backup /etc /var/www /home /var/backups/db
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune

5. Timeshift, Déjà Dup, and Cloud/LVM Snapshots

Déjà Dup targets GNOME desktop folders, not headless servers. Timeshift takes local Rsync or Btrfs system snapshots (also usable via CLI), but excludes /home and /root by default and lacks encrypted offsite storage. Similarly, VPS, LVM, and ZFS snapshots help roll back botched updates quickly, but they live on the same host or cloud account and do not replace independent offsite backups.

Backing Up MySQL, MariaDB, and PostgreSQL Safely

Copying /var/lib/mysql or /var/lib/postgresql on a live server risks inconsistent tables. Export logical dumps into a root-only directory right before your file backup runs:

sudo install -d -m 0700 /var/backups/db

# MySQL (use mariadb-dump on MariaDB)
mysqldump --single-transaction --routines --triggers --all-databases \
  | gzip > /var/backups/db/mysql-all-$(date +%F).sql.gz

# PostgreSQL
sudo -u postgres pg_dump -Fc mydb > /var/backups/db/mydb-$(date +%F).dump
sudo -u postgres pg_dumpall | gzip > /var/backups/db/pg-all-$(date +%F).sql.gz

Running WordPress on Ubuntu? Pair these database dumps with our WordPress backup guide.

Automating Backups with systemd Timers (and Cron)

systemd timers beat bare cron jobs on Ubuntu 24.04 and 26.04 because output goes straight to journalctl and Persistent=true catches missed runs after reboots. Put your backup script at /usr/local/sbin/run-ubuntu-backup.sh (chmod 700) and create a unit pair:

# /etc/systemd/system/ubuntu-backup.service
[Unit]
Description=Daily Ubuntu Server Backup
After=network-online.target
Wants=network-online.target

[Service]
Type=oneshot
EnvironmentFile=/etc/default/ubuntu-backup
ExecStart=/usr/local/sbin/run-ubuntu-backup.sh

# /etc/systemd/system/ubuntu-backup.timer
[Unit]
Description=Run Ubuntu Server Backup Daily

[Timer]
OnCalendar=*-*-* 02:30:00
RandomizedDelaySec=15m
Persistent=true

[Install]
WantedBy=timers.target
sudo systemctl daemon-reload
sudo systemctl enable --now ubuntu-backup.timer
journalctl -u ubuntu-backup.service -n 40

Prefer cron? Call the same script from sudo crontab -e (30 2 * * * /usr/local/sbin/run-ubuntu-backup.sh >/var/log/ubuntu-backup.log 2>&1) rather than putting inline date +%F commands inside crontab.

Securing Backups Against Ransomware

CISA’s #StopRansomware Guide warns that intruders actively delete reachable backups. Lock down your backup targets:

  • Make offsite storage append-only or immutable: Restrict Borg SSH keys with command="borg serve --append-only --restrict-to-path /srv/borg/web01",restrict, use Restic’s append-only REST server, or enable S3 Object Lock so a compromised host cannot erase past snapshots.
  • Keep recovery keys off the server: Store Borg key exports and passphrases in a password manager—not only on the host being backed up.
  • Lock down credential files: Keep /etc/default/ubuntu-backup owned by root:root with permissions 0600.
  • Harden the server itself: Follow our Ubuntu server security guide and ransomware prevention guide.

Testing Your Restores

Verify repository integrity weekly and test real restores into a temporary directory or staging VM quarterly:

# Borg integrity check + test extract
borg check ssh://borg@backup.example.com:22/srv/borg/web01
mkdir -p /tmp/restore-test && cd /tmp/restore-test
borg extract ssh://borg@backup.example.com:22/srv/borg/web01::"web01-2026-11-25" etc/nginx

# Restic integrity check + test restore
restic check --read-data-subset=5%
restic restore latest --target /tmp/restore-test --include /etc/nginx

# Test database restore
gunzip < /tmp/restore-test/var/backups/db/mysql-all-2026-11-25.sql.gz | sudo mysql
sudo -u postgres pg_restore -d mydb_test /tmp/restore-test/var/backups/db/mydb-2026-11-25.dump

FAQ

What is the best Ubuntu backup tool for a production server?

BorgBackup (for SSH servers) and Restic (for S3/cloud object storage) are top choices because both provide client-side encryption, deduplication, and automated pruning.

Should I use Timeshift or Déjà Dup on Ubuntu Server?

Déjà Dup is a desktop app. Timeshift works on the CLI for local OS rollbacks, but it excludes /home and /root by default and does not replace encrypted offsite backups.

Are VPS or cloud snapshots enough?

No. Snapshots live inside the same cloud account and hypervisor; keep an independent encrypted offsite copy under separate credentials.

Why use mysqldump or pg_dump instead of copying /var/lib/mysql?

Copying active database files can capture half-written pages and corrupt tables. Logical dumps produce consistent, restorable snapshots.

How often should I back up an Ubuntu server?

Run encrypted incremental backups at least daily, take an extra snapshot before major upgrades, and dump busy databases hourly or ship WAL/binlogs.

How do I protect Ubuntu backups from ransomware?

Use append-only SSH keys or S3 Object Lock, keep passphrases off the server, and maintain one offline or air-gapped copy.

References

Related Articles

Last Verified: November 25, 2026. Verified for Ubuntu 24.04 LTS and Ubuntu 26.04 LTS against Ubuntu Server documentation, BorgBackup, Restic, PostgreSQL, systemd, and CISA guidance.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *