Sub topic 6
Running your first backup
This chapter assumes you can use the Linux command line, log in with SSH keys, read basic file permissions, and work with systemd. It also assumes that you have installed either restic or Borg and initialized an encrypted repository. The repository is the storage location where snapshots or archives are kept.
Select the data
A server backup should begin with a deliberate list of paths. For a typical web server, /etc contains configuration, /home contains user data, and /var/www contains site files.
Do not automatically back up every directory under /. Runtime data such as /proc, /sys, /dev, and /run is generated by the running kernel and services. Temporary files and caches can also waste backup space.
Create an exclusion file for restic:
# /etc/restic/excludes.txt
/var/cache
/var/tmp
/tmp
/home/*/.cacheReview the exclusions before using them. An excluded path cannot be restored from this repository.
Create a restic snapshot
Set the repository and password file in the shell. The password file should be readable only by root.
export RESTIC_REPOSITORY=sftp:[email protected]:/srv/restic/myserver
export RESTIC_PASSWORD_FILE=/etc/restic/password
restic backup \
--exclude-file=/etc/restic/excludes.txt \
/etc /home /var/www
restic snapshotsrestic backup reads the selected paths, encrypts and deduplicates their contents, and creates a snapshot. A snapshot records the source paths, host, time, and saved data. restic snapshots displays the snapshot identifier that you can use during a restore.
If the command fails, read the error before retrying. A network failure may leave an incomplete operation, but rerunning the backup is normally safe. Restic reuses data that is already stored.
Create a Borg archive
Borg uses an archive inside a repository for each backup run. Configure the repository and passphrase command, then create an archive:
export BORG_REPO=ssh://[email protected]/./borg/myserver
export BORG_PASSCOMMAND='cat /etc/borg/passphrase'
borg create --stats --compression zstd \
'::{hostname}-{now:%Y-%m-%dT%H:%M:%S}' \
/etc /home /var/www
borg listThe archive name includes the host and timestamp. --stats reports how much data Borg processed and stored. --compression zstd reduces stored size when the data compresses well.
Borg and restic both deduplicate chunks. If a file is unchanged, a later run stores references to existing chunks instead of storing the same content again. Deduplication reduces space usage, but it does not remove the need for multiple recovery points.
Check the result
Confirm that the command completed successfully and that a new snapshot or archive appears. Record the identifier and inspect its contents before relying on the backup.
For restic:
restic ls latest /etcFor Borg:
borg list ::
borg list '::myserver-2026-11-27T02:00:00'A successful backup command proves that data was uploaded. It does not prove that the data can be restored correctly. Test a small restore in a temporary directory before automating the job.
Exercise
Which three paths does this chapter back up, and why should /proc normally be excluded?
Show answer
It backs up /etc, /home, and /var/www. /proc is a virtual filesystem generated by the running kernel, so its contents are not ordinary persistent files that should be archived.