Sub topic 2
Running your first backup
This chapter assumes you have a restic repository set up as described in the previous chapter, that you can run commands with sudo, and that you know basic SSH key login and file permissions. Borg equivalents are noted where they differ.
Running your first backup
A snapshot is a record of the paths you backed up at one point in time. Restic stores snapshots in an encrypted, deduplicated repository. Deduplication means identical data is stored once, even across many snapshots.
Set the repository location and password file, then run the backup:
export RESTIC_REPOSITORY=sftp:[email protected]:/srv/restic/myserver
export RESTIC_PASSWORD_FILE=/etc/restic/password
restic backup /etc /home /var/www
restic snapshotsThe first run uploads everything. Later runs upload only changed data.
Deciding what to include and exclude
Back up what you cannot rebuild, such as configuration, user data, and application files. Skip caches, temporary files, and logs. Put exclusion patterns in a file, one per line:
*.tmp
/var/www/cachePass the file to the backup command:
restic backup --exclude-file=/etc/restic/excludes.txt /etc /home /var/wwwBrowsing and restoring files
List a snapshot's contents before you restore anything:
restic ls latest /etc/nginxRestore into a scratch directory, not over live files:
restic restore latest --target /tmp/restore --include /etc/nginxCheck the files in /tmp/restore, then copy what you need into place. With Borg, change into the target directory first, because borg extract writes to the current directory.
Retention policies and reclaiming space
Each backup adds a snapshot, and old snapshots keep data in use. A retention policy defines which snapshots to keep. forget removes snapshot records. --prune then deletes data that no remaining snapshot uses:
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --pruneWith Borg, run borg prune with the same keep options, then borg compact (Borg 1.2 and later) to free the space.
Exercise
Why does restic forget without --prune leave disk usage unchanged?
Show answer
It removes only the snapshot records. The data stays in the repository until a prune step deletes blocks that no remaining snapshot references.