Sub topic 3
How repositories, snapshots and deduplication work
Assume you are comfortable with the Linux command line, SSH, file permissions, and the roles of /etc, /home, and /var. You should also know basic systemd concepts. This chapter focuses on the storage model behind restic and Borg, so you can predict what commands will do before using them.
The repository is the backup database
A repository is the directory or remote storage location that contains backup data and its metadata. You initialize it once with a tool such as restic init or borg init.
A repository normally contains:
- Encrypted data chunks.
- Metadata describing snapshots or archives.
- Indexes that map stored chunks to backup contents.
- Repository configuration and integrity information.
The repository is separate from the source paths being backed up. For example, /etc remains on the server, while the repository might be on another server accessed through SFTP or SSH.
Both tools encrypt data on the client before sending it to the repository. The remote host does not need the repository passphrase to store the encrypted content. Losing the passphrase can make the backup unrecoverable.
Snapshots, archives, and chunks
A snapshot is restic's record of a backup at a point in time. It includes information such as the host, timestamp, selected paths, and a tree describing files and directories.
Borg uses the term archive for a similar object. An archive also points to stored file data and records the state of the selected paths at one time.
Neither a snapshot nor an archive usually contains a complete independent copy of every file. Instead, it references encrypted chunks. A chunk is a piece of file data stored in the repository.
Deduplication and repository growth
Deduplication means storing identical content once even when it appears in multiple backups. If a file does not change, a later snapshot can reference its existing chunks. This reduces storage use and upload time.
Deduplication is content-based rather than based only on file names. Two files with the same content can share chunks, and a renamed file may still reuse its data.
Changing a small part of a large file can require new chunks. The exact amount depends on the tool's chunking algorithm and where the change occurs. Databases and virtual-machine images can therefore produce more repository growth than many small text files.
Deleting a snapshot does not necessarily delete its chunks. A chunk may be referenced by another snapshot. Even unreferenced chunks usually remain until cleanup runs:
| Tool | Remove snapshots or archives | Reclaim unreferenced data |
|---|---|---|
| restic | `forget` | `prune` |
| Borg | `prune` | `compact` in Borg 1.2 and later |
Encryption and common errors
Encryption protects the repository from someone who can read its storage. It does not protect a running server whose files are already compromised. Keep the repository passphrase in a root-readable file or another protected secret store, and keep a separate recovery copy of required keys.
Common mistakes include:
- Treating a snapshot as a full independent backup.
- Running cleanup without understanding the retention policy.
- Assuming deduplication works between unrelated repositories.
- Deleting the only copy of the passphrase.
- Copying a live database's data directory and assuming it is consistent.
A repository is also a failure boundary. If every snapshot exists in one repository on one disk, corruption or deletion can affect all restore points. Keep another repository or storage copy, preferably in a different location.
A practical inspection
After creating backups, inspect the logical records rather than browsing repository files directly:
restic snapshots
borg listRestic lists snapshots, while Borg lists archives. The repository's internal files are implementation details. Do not edit or remove them manually.
Exercise
Why can deleting an old snapshot fail to reduce repository size immediately?
Show answer
Its chunks may still be referenced by other snapshots, or unreferenced chunks may remain until restic prune or Borg compact runs.