Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
en:backup:server [2022/02/26 23:07] – added syncthing dan | en:backup:server [2022/10/24 08:24] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 110: | Line 110: | ||
===== borg ===== | ===== borg ===== | ||
- | |||
- | <alert type=" | ||
Follow our [[en: | Follow our [[en: | ||
Line 117: | Line 115: | ||
The snapshots are stored remotely via ssh. | The snapshots are stored remotely via ssh. | ||
+ | ==== Script ==== | ||
+ | |||
+ | Don't forget to create the borg repo first and add the credentials to the script. | ||
+ | < | ||
+ | borg init --encryption=keyfile-blake2 --make-parent-dirs ssh:// | ||
+ | </ | ||
+ | |||
+ | Add your excluded folders/ | ||
+ | < | ||
+ | #!/bin/sh | ||
+ | |||
+ | # Setting this, so the repo does not need to be given on the commandline: | ||
+ | export BORG_REPO=ssh:// | ||
+ | |||
+ | # See the section " | ||
+ | export BORG_PASSPHRASE=' | ||
+ | |||
+ | # some helpers and error handling: | ||
+ | info() { printf "\n%s %s\n\n" | ||
+ | trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM | ||
+ | |||
+ | info " | ||
+ | |||
+ | # Backup the most important directories into an archive named after | ||
+ | # the machine this script is currently running on: | ||
+ | |||
+ | borg create | ||
+ | --verbose | ||
+ | --filter AMEhsx | ||
+ | --list | ||
+ | --stats | ||
+ | --progress | ||
+ | --verbose | ||
+ | --show-version | ||
+ | --show-rc | ||
+ | --compression zstd, | ||
+ | --exclude-caches | ||
+ | --exclude '/ | ||
+ | --exclude '/ | ||
+ | \ | ||
+ | ::' | ||
+ | /etc \ | ||
+ | /home \ | ||
+ | /root \ | ||
+ | /var \ | ||
+ | |||
+ | backup_exit=$? | ||
+ | |||
+ | info " | ||
+ | |||
+ | # Use the `prune` subcommand to maintain 7 daily, 4 weekly and 6 monthly | ||
+ | # archives of THIS machine. The ' | ||
+ | # limit prune' | ||
+ | # other machines' | ||
+ | |||
+ | borg prune \ | ||
+ | --list | ||
+ | --prefix ' | ||
+ | --show-rc | ||
+ | --keep-daily | ||
+ | --keep-weekly | ||
+ | --keep-monthly | ||
+ | --keep-yearly | ||
+ | |||
+ | prune_exit=$? | ||
+ | |||
+ | # use highest exit code as global exit code | ||
+ | global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit )) | ||
+ | |||
+ | if [ ${global_exit} -eq 0 ]; then | ||
+ | info " | ||
+ | elif [ ${global_exit} -eq 1 ]; then | ||
+ | info " | ||
+ | else | ||
+ | info " | ||
+ | fi | ||
+ | exit ${global_exit} | ||
+ | </ | ||
===== Crontab - rsync and borg ===== | ===== Crontab - rsync and borg ===== | ||