This article covers How to Back Up an Ubuntu in detail. An Ubuntu server backup with Restic gives you encrypted, deduplicated, snapshot-based backups in a single self-contained tool. Simple cp or rsync scripts copy files, but they do not encrypt them, they store every version in full, and restoring “the state from last Tuesday” is guesswork. Restic solves all three problems: every backup is a snapshot you can browse or restore, unchanged data is stored only once, and everything in the repository is encrypted with a password only you know. This guide builds a complete Ubuntu server backup with Restic, from the first snapshot to automated daily runs with retention rules.
Why Choose Restic for Ubuntu Server Backup? – How to Back Up an Ubuntu
Restic is written in Go, ships as one binary and supports local disks, SFTP servers and S3-compatible object storage without plugins. Its deduplication works at the block level, so a 40 GB server whose files barely change might add only a few hundred megabytes per daily snapshot. Snapshots are cheap to keep and cheap to verify with the built-in check command. If you currently copy files with scripts, our rsync and cron backup guide is a good comparison point; many administrators run rsync for quick mirrors and Restic for the encrypted, versioned archive.
Prerequisites – How to Back Up an Ubuntu
- An Ubuntu 20.04, 22.04 or 24.04 server with
sudoaccess. - Backup storage: a second disk, a mounted external drive, or another server reachable by SSH. Never keep the only backup on the same disk as the data.
- A strong repository password stored in a password manager. Lose it and the backup is unrecoverable by design.
Step 1: Install Restic
sudo apt update
sudo apt install restic -y
restic version
Step 2: Initialize the Repository
Create the repository directory (adjust the path to your storage) and initialize it. You will be asked to set the encryption password:
sudo mkdir -p /mnt/backup/restic-repo
sudo restic -r /mnt/backup/restic-repo init
To avoid typing the password in every command, store it in a root-only file and reference it:
echo 'ChooseAVeryStrongPassword' | sudo tee /root/.restic-password > /dev/null
sudo chmod 600 /root/.restic-password
export RESTIC_PASSWORD_FILE=/root/.restic-password
export RESTIC_REPOSITORY=/mnt/backup/restic-repo

Step 3: Take Your First Snapshot
Back up the directories that define your server. Configuration, web roots and home directories are the usual minimum; databases should also be dumped to files first so Restic captures a consistent copy:
sudo -E restic backup /etc /var/www /home /root --exclude-caches
The first run uploads everything and can take a while. Later runs only transfer new and changed blocks, so they finish in seconds or minutes. List what you have:
sudo -E restic snapshots
Step 4: Verify and Explore Snapshots
Regularly prove the repository is healthy, and peek inside a snapshot without restoring it:
sudo -E restic check
sudo -E restic ls latest /etc
You can also mount the entire repository as a read-only filesystem with restic mount /mnt/restore and copy individual files with normal tools, which is the most comfortable way to recover a single configuration file at 3 a.m.
Step 5: Restore Data
Restore the newest snapshot into a scratch directory and pick what you need, rather than overwriting live data blindly:
sudo -E restic restore latest --target /tmp/restore-test
ls /tmp/restore-test/etc
Use --include to restore a single path, and test restores regularly: an untested backup is a hope, not a backup.
Step 6: Apply a Retention Policy
Snapshots accumulate forever unless you prune them. A common policy keeps a week of daily, a month of weekly and half a year of monthly snapshots:
sudo -E restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune
The forget command marks snapshots outside the policy and --prune actually frees the space by repacking the repository.
Step 7: Automate with a systemd Timer
Create /etc/systemd/system/restic-backup.service:
[Unit]
Description=Restic backup
After=network-online.target
[Service]
Type=oneshot
Environment="RESTIC_PASSWORD_FILE=/root/.restic-password"
Environment="RESTIC_REPOSITORY=/mnt/backup/restic-repo"
ExecStart=/usr/bin/restic backup /etc /var/www /home --exclude-caches
ExecStart=/usr/bin/restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune
And a timer /etc/systemd/system/restic-backup.timer that runs it nightly:
[Unit]
Description=Nightly Restic backup
[Timer]
OnCalendar=*-*-* 02:30:00
Persistent=true
[Install]
WantedBy=timers.target
sudo systemctl daemon-reload
sudo systemctl enable --now restic-backup.timer
If timers are new to you, our systemd on Ubuntu guide explains units and timers in depth.
Troubleshooting
“Repository is already locked”. A crashed run left a stale lock. After confirming no backup is running, clear it with restic unlock.
“Wrong password or no key found”. The password file does not match the one used at init. There is no backdoor; restore the correct password from your password manager.
Backups keep growing too fast. Log files and caches churn constantly. Exclude them with --exclude-caches and explicit --exclude patterns for /var/log if you do not need logs in the archive.
Conclusion
An Ubuntu server backup with Restic is encrypted, space-efficient and honest about restores: snapshots you can list, check, mount and recover from. Initialize the repository on separate storage, automate nightly snapshots with a systemd timer, prune with a clear retention policy and rehearse a restore before you ever need one. The official reference for backends and advanced options is the Restic manual.