Sub topic 6
Running your first backup
This chapter assumes you have already initialized a repository (restic or Borg 1.x) and can reach it from the server, either locally or over SSH. It also assumes the passphrase is available through RESTIC_PASSWORD_FILE or BORG_PASSCOMMAND. You should be comfortable reading shell exit codes and file permissions. Exclusion patterns, restores, and retention each have their own chapters, so this one covers only the first run and how to judge whether it worked.
What happens during a backup run
Both tools follow the same sequence. They walk the paths you give them and split each file into chunks. They hash each chunk and check whether the repository already holds a chunk with that hash. Only new chunks are compressed (Borg by default if you ask, restic by default in repository format 2), encrypted, and uploaded. Last, they write a small record listing which chunks make up which files. That record is a snapshot in restic and an archive in Borg.
Because of the hash check, the first run is the slowest and largest. Later runs transfer only what changed, yet each one still produces a complete snapshot you can restore on its own.
Running restic
Set the repository and password variables, then back up three directories. These are the same variables you used for restic init.
export RESTIC_REPOSITORY=sftp:[email protected]:/srv/restic/myserver
export RESTIC_PASSWORD_FILE=/etc/restic/password
restic init
restic backup /etc /home /var/www
restic snapshotsSkip restic init if the repository already exists. Running it again on an existing repository fails with an error and changes nothing.
Run the command as root. Files such as /etc/shadow and other users' home directories are unreadable to normal users, and a backup that silently skips them is worse than one that fails loudly.
The summary at the end of restic backup shows the fields worth reading:
- Files: N new, N changed, N unmodified tells you how much restic had to look at. On a first run, everything is new.
- Added to the repository is the size of new data after compression and deduplication. It is usually smaller than the processed size.
- snapshot abc12345 saved confirms the snapshot was written. Without this line, nothing is restorable from this run.
restic snapshots then lists each snapshot with its short ID, time, host, and paths. The host and paths matter later, because restic uses them to group snapshots when you apply retention.
Running Borg
Borg 1.x uses the same pattern with different names. This example uses a passphrase read by a command, so no secret appears in the environment listing.
export BORG_REPO=ssh://[email protected]/./borg/myserver
export BORG_PASSCOMMAND='cat /etc/borg/passphrase'
borg init --encryption=repokey-blake2
borg create --stats --compression zstd '::{hostname}-{now:%Y-%m-%dT%H:%M:%S}' /etc /home /var/www
borg listThree details in the borg create line trip people up:
- The
::prefix means "the repository named inBORG_REPO". The text after it is the archive name. {hostname}and{now:...}are Borg placeholders, expanded by Borg itself. Keep the argument in single quotes so the shell does not treat the braces as its own expansion.- Archive names must be unique within the repository. A timestamp down to the second keeps them unique. A fixed name like
::dailywould fail on the second run.
--compression zstd is a choice, not a requirement. Borg 1.x defaults to lz4, which is fast and compresses lightly. Zstandard compresses better at a moderate CPU cost, and for a nightly job on a server that is usually a good trade.
Comparing the two runs
| Aspect | restic | Borg 1.x |
|---|---|---|
| Command | `restic backup PATHS` | `borg create ::NAME PATHS` |
| Identity of a run | Snapshot with a generated ID | Archive with a name you choose |
| Summary output | Printed by default | Needs `--stats` |
| List results | `restic snapshots` | `borg list` |
| Path stored | Absolute, such as `/etc/nginx` | Relative, such as `etc/nginx` |
The last row matters when you restore. Borg strips the leading slash when it stores paths, so you ask for etc/nginx, not /etc/nginx.
Preview before committing
For a large first backup, preview what will be included. Both tools can do a dry run.
restic backup --dry-run --verbose /etc /home /var/www
borg create --dry-run --list --filter=AME '::{hostname}-test' /etc /home /var/wwwThe restic form requires version 0.14 or later. Borg's --list prints one line per file with a status letter, and --filter=AME limits output to added (A), modified (M), and error (E) entries. In a dry run, nothing is written to the repository.
A dry run is also the cheapest way to find directories you did not mean to include, such as a cache that holds tens of gigabytes. Decide on exclusions in the next chapter before the first real run if the preview shows surprises.
Checking that the run succeeded
Do not judge success by the absence of red text. Check the exit status.
restic backup /etc /home /var/www
echo "restic exit status: $?"The meanings differ slightly between the tools.
| Exit status | restic | Borg |
|---|---|---|
| 0 | Snapshot saved, all files read | Archive created without problems |
| 1 | Fatal error, no snapshot | Warning: archive created, but something was off, such as a file that changed while being read |
| 2 | Not used for backup failures (reserved for Go runtime errors) | Error: the operation failed |
| 3 | Snapshot saved, but some files could not be read | Not used |
Treat restic status 3 and Borg status 1 as "a backup exists, and you need to read the messages". A common cause is a file that disappeared or changed mid-run, such as a log file or temporary file. That is normal for a live server. A permission error on a path you care about is not normal, and it means the job is running as the wrong user.
Running a second time
Run the same command again right away. The second run should finish much faster, and the summary should show nearly everything as unmodified (restic) or a tiny "This archive" deduplicated size (Borg). In Borg's --stats output, the "Deduplicated size" column for "This archive" shows how little new data the run added.
This is the quickest check that deduplication works in your setup. If the second run is as large as the first, something is changing the files, or you may be pointing at a different repository than you think. Check RESTIC_REPOSITORY or BORG_REPO in the shell that ran the command.
Common first-run errors
- "wrong password or no key found" (restic) or "passphrase supplied in BORG_PASSPHRASE... is incorrect" (Borg). The password file or command returns something different from what you used at
init. Watch for a trailing newline you added by hand, or the wrong file. - "repository does not exist" or "is not a valid repository". The path or URL is wrong. For Borg over SSH,
./borg/myserveris relative to the remote user's home directory, while/borg/myserveris absolute. - "unable to create lock" or "Failed to create/acquire the lock". Another backup is still running, or an earlier run was killed and left a lock behind. Confirm no backup process is alive before removing a lock with
restic unlockorborg break-lock. - Permission denied on many files. You are not running as root, or the paths sit on a mount that root cannot read, such as some network file systems.
- SSH prompts for a password or host key. The backup user's key login is not working non-interactively. Fix this before automating, because a timer cannot answer prompts.
Verifying the result cheaply
After the first run, list a known file from the newest backup to confirm it is really in there.
restic ls latest /etc/hostname
borg list '::{hostname}-2026-11-27T02:00:00' etc/hostnameReplace the Borg archive name with one shown by borg list. This confirms that the file exists in the snapshot. It does not test restoring, which later chapters cover, but it takes seconds and catches the wrong-path mistakes that are most common on a first run.
Exercise
You run borg create --stats --compression zstd '::daily' /etc twice in a row and the second command fails. What is the cause, and how do you fix it? Then explain what exit status you would expect from restic if one file under /var/www was unreadable but a snapshot was saved.
Show answer
Borg archive names must be unique in a repository, and ::daily already exists after the first run. Use a name with a changing part, for example '::{hostname}-{now:%Y-%m-%dT%H:%M:%S}'. For restic, a saved snapshot with at least one unreadable source file returns exit status 3, which means a backup exists but the messages need review.