Prefix envvars with RESTIC_ for consistencty

Fix #63
This commit is contained in:
Erik Westrup
2022-02-01 16:59:12 +01:00
parent 4e8b8adff6
commit 79d13a1e64
4 changed files with 30 additions and 21 deletions

View File

@@ -11,7 +11,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Assertion on all needed envionment variables in the backup and check scripts.
### Changed
- **BREAKING CHANGE** renamed `/etc/restic/backup_exclude` to `/etc/restic/backup_exclude.txt` and ditto for `<backup-dest>/.backup_exclude` to `<backup-dest>/.backup_exclude.txt`.
- **BREAKING CHANGE** renamed
- `/etc/restic/backup_exclude` to `/etc/restic/backup_exclude.txt`
- `<backup-dest>/.backup_exclude` to `<backup-dest>/.backup_exclude.txt`.
- **BREAKING CHANGE** renamed envvars for consistency
- `BACKUP_PATHS` -> `RESTIC_BACKUP_PATHS`
- `BACKUP_TAG` -> `RESTIC_BACKUP_TAG`
- `RETENTION_DAYS` -> `RESTIC_RETENTION_DAYS`
- `RETENTION_WEEKS` -> `RESTIC_RETENTION_WEEKS`
- `RETENTION_MONTHS` -> `RESTIC_RETENTION_MONTHS`
- `RETENTION_YEARS` -> `RESTIC_RETENTION_YEARS`
- Align terminology used in README with the one used by B2 for credentials (keyId + applicationKey pair).
## [2.0.0] - 2022-02-01

View File

@@ -125,7 +125,7 @@ Put this file in `/usr/local/sbin`:
Restic support exclude files. They list file pattern paths to exclude from you backups, files that just occupy storage space, backup-time, network and money. `restic_backup.sh` allows for a few different exclude files.
* `/etc/restic/backup_exclude.txt` - global exclude list. You can use only this one if your setup is easy. This is set in `_global.env`. If you need a different file for another profile, you can override the envvar `RESTIC_BACKUP_EXCLUDE_FILE` in this profile.
* `.backup_exclude.txt` per backup path. If you have e.g. an USB disk mounted at /mnt/media and this path is included in the `$BACKUP_PATHS`, you can place a file `/mnt/media/.backup_exclude.txt` and it will automatically picked up. The nice thing about this is that the backup paths are self-contained in terms of what they shoud exclude!
* `.backup_exclude.txt` per backup path. If you have e.g. an USB disk mounted at /mnt/media and this path is included in the `$RESTIC_BACKUP_PATHS`, you can place a file `/mnt/media/.backup_exclude.txt` and it will automatically picked up. The nice thing about this is that the backup paths are self-contained in terms of what they shoud exclude!
## 5. Make first backup
Now see if the backup itself works, by running as root

View File

@@ -17,21 +17,21 @@ export RESTIC_REPOSITORY="b2:<b2-repo-name>" # TODO fill with your repo name
# What to backup (paths our mountpoints) e.g. "/ /boot /home /mnt/media".
# To backup only your home directory, set "/home/your-user"
export BACKUP_PATHS="" # TODO fill conveniently with one or multiple paths
export RESTIC_BACKUP_PATHS="" # TODO fill conveniently with one or multiple paths
# Example below of how to dynamically add a path that is mounted e.g. external USB disk.
# restic does not fail if a specified path is not mounted, but it's nicer to only add if they are available.
#test -d /mnt/media && BACKUP_PATHS+=" /mnt/media"
#test -d /mnt/media && RESTIC_BACKUP_PATHS+=" /mnt/media"
# A tag to identify backup snapshots.
export BACKUP_TAG=systemd.timer
export RESTIC_BACKUP_TAG=systemd.timer
# Retention policy - How many backups to keep.
# See https://restic.readthedocs.io/en/stable/060_forget.html?highlight=month#removing-snapshots-according-to-a-policy
export RETENTION_DAYS=14
export RETENTION_WEEKS=16
export RETENTION_MONTHS=18
export RETENTION_YEARS=3
export RESTIC_RETENTION_DAYS=14
export RESTIC_RETENTION_WEEKS=16
export RESTIC_RETENTION_MONTHS=18
export RESTIC_RETENTION_YEARS=3
# Optional extra arguments to restic-backup.
# Example: Add two additional exclude files to the global one in RESTIC_PASSWORD_FILE.

View File

@@ -26,9 +26,9 @@ assert_envvars() {
}
assert_envvars \
B2_ACCOUNT_ID B2_ACCOUNT_KEY B2_CONNECTIONS \
BACKUP_PATHS BACKUP_TAG \
RESTIC_BACKUP_PATHS RESTIC_BACKUP_TAG \
RESTIC_BACKUP_EXCLUDE_FILE RESTIC_BACKUP_EXTRA_ARGS RESTIC_PASSWORD_FILE RESTIC_REPOSITORY RESTIC_VERBOSITY_LEVEL \
RETENTION_DAYS RETENTION_MONTHS RETENTION_WEEKS RETENTION_YEARS
RESTIC_RETENTION_DAYS RESTIC_RETENTION_MONTHS RESTIC_RETENTION_WEEKS RESTIC_RETENTION_YEARS
@@ -46,9 +46,9 @@ trap exit_hook INT TERM
# NOTE that restic will fail the backup if not all listed --exclude-files exist. Thus we should only list them if they are really all available.
## Global backup configuration.
exclusion_args="--exclude-file ${RESTIC_BACKUP_EXCLUDE_FILE}"
## Self-contained backup files per backup path. E.g. having an USB disk at /mnt/media in BACKUP_PATHS,
## Self-contained backup files per backup path. E.g. having an USB disk at /mnt/media in RESTIC_BACKUP_PATHS,
# a file /mnt/media/.backup_exclude.txt will automatically be detected and used:
for backup_path in ${BACKUP_PATHS[@]}; do
for backup_path in ${RESTIC_BACKUP_PATHS[@]}; do
if [ -f "$backup_path/.backup_exclude.txt" ]; then
exclusion_args+=" --exclude-file $backup_path/.backup_exclude.txt"
fi
@@ -65,16 +65,16 @@ wait $!
# Do the backup!
# See restic-backup(1) or http://restic.readthedocs.io/en/latest/040_backup.html
# --one-file-system makes sure we only backup exactly those mounted file systems specified in $BACKUP_PATHS, and thus not directories like /dev, /sys etc.
# --one-file-system makes sure we only backup exactly those mounted file systems specified in $RESTIC_BACKUP_PATHS, and thus not directories like /dev, /sys etc.
# --tag lets us reference these backups later when doing restic-forget.
restic backup \
--verbose=$RESTIC_VERBOSITY_LEVEL \
--one-file-system \
--tag $BACKUP_TAG \
--tag $RESTIC_BACKUP_TAG \
--option b2.connections=$B2_CONNECTIONS \
$exclusion_args \
$RESTIC_BACKUP_EXTRA_ARGS \
$BACKUP_PATHS &
$RESTIC_BACKUP_PATHS &
wait $!
# Dereference and delete/prune old backups.
@@ -82,14 +82,14 @@ wait $!
# --group-by only the tag and path, and not by hostname. This is because I create a B2 Bucket per host, and if this hostname accidentially change some time, there would now be multiple backup sets.
restic forget \
--verbose=$RESTIC_VERBOSITY_LEVEL \
--tag $BACKUP_TAG \
--tag $RESTIC_BACKUP_TAG \
--option b2.connections=$B2_CONNECTIONS \
--prune \
--group-by "paths,tags" \
--keep-daily $RETENTION_DAYS \
--keep-weekly $RETENTION_WEEKS \
--keep-monthly $RETENTION_MONTHS \
--keep-yearly $RETENTION_YEARS &
--keep-daily $RESTIC_RETENTION_DAYS \
--keep-weekly $RESTIC_RETENTION_WEEKS \
--keep-monthly $RESTIC_RETENTION_MONTHS \
--keep-yearly $RESTIC_RETENTION_YEARS &
wait $!
# Check repository for errors.