Sub topic 7
Deciding what to include and exclude
Assume you are comfortable with the Linux command line, file permissions, SSH, and the roles of /etc, /home, and /var. This chapter assumes that restic or Borg is already installed and that you have an initialized repository.
A useful backup set contains everything needed to rebuild the server and restore user data. It should not contain temporary files that waste storage or change while the backup runs.
Start with a recovery list
Think about what you must restore after disk failure:
/etcfor service configuration, users, scheduled jobs, and network settings./homefor user documents and SSH configuration./var/www,/srv, or another application directory for site data./var/libfor application state, unless the application has a better backup method./rootfor administrative scripts and configuration.- Database dumps created with a database tool.
Do not assume that backing up a package list is enough. A package list tells you what to install, but it does not preserve configuration or application data.
Some paths should usually be excluded:
- Caches such as
/var/cache. - Temporary data under
/tmpand/var/tmp. - Runtime state under
/run. - Mounted removable disks or network shares that are not part of this server.
- Build directories and dependency caches.
- Database data files when you are backing up a consistent database dump instead.
Use care with logs. Logs can help diagnose an incident, but they may consume much of the repository. Keep them if your recovery plan requires them, or exclude old logs with a deliberate policy.
| Path type | Typical decision | Reason |
|---|---|---|
| `/etc` | Include | Required to rebuild services |
| `/home` | Include | Contains user data |
| `/tmp` | Exclude | Temporary runtime data |
| Database dump | Include | Consistent, portable database backup |
| Live database files | Usually exclude | May be inconsistent while changing |
Use an exclusion file
An exclusion file makes the backup policy visible and reviewable. For restic, each line can contain a path or pattern:
/tmp
/var/tmp
/var/cache
/run
/home/*/.cache
/var/log/journalRun a backup with that file:
restic backup --exclude-file=/etc/restic/excludes.txt /etc /home /var/www /rootRestic also supports command-line exclusions, but putting stable rules in a root-readable file avoids long commands.
Borg uses an exclusion file with its own pattern syntax. A simple file can use absolute paths:
pp:/tmp
pp:/var/tmp
pp:/var/cache
pp:/run
pp:/home/*/.cacheThe pp: prefix means “parent path.” It matches the named path and its contents. Use it with Borg like this:
borg create --exclude-from=/etc/borg/excludes.txt \
'::{hostname}-{now:%Y-%m-%dT%H:%M:%S}' \
/etc /home /var/www /rootCheck each tool’s pattern rules before translating an exclusion file from one tool to the other. Similar-looking patterns do not always have identical meanings.
Test the policy
Review what a backup would contain before trusting the policy. For restic, use --dry-run:
restic backup --dry-run --exclude-file=/etc/restic/excludes.txt \
/etc /home /var/www /rootFor Borg, use --list and inspect the output of a test archive. Confirm that required configuration and application files appear, while caches and runtime paths do not.
Exercise
Why is a database dump usually preferable to copying live database files?
Show answer
A dump is created by the database system and represents a consistent logical state. Live data files can change during copying and may not restore cleanly.