From b8bd8d326692e9a0fad0fa5f2e25bd446d846c4d Mon Sep 17 00:00:00 2001 From: Felix Van der Jeugt Date: Fri, 7 May 2021 00:01:51 +0200 Subject: [PATCH] add initial backup script --- local/bin/backup | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100755 local/bin/backup diff --git a/local/bin/backup b/local/bin/backup new file mode 100755 index 0000000..3664450 --- /dev/null +++ b/local/bin/backup @@ -0,0 +1,75 @@ +#!/bin/sh + +export BORG_REPO=ssh://Caret/home/ninewise/borg +export BORG_PASSPHRASE="$(pass show borg)" + +info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; } +trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM + +info "Starting backup" + +borg create \ + --verbose \ + --filter AME \ + --list \ + --stats \ + --show-rc \ + --compression lz4 \ + --exclude-caches \ + --exclude '/etc/sv/*/supervise' \ + --exclude '/var/tmp/*' \ + --exclude '/var/db/*' \ + --exclude '/var/cache' \ + --exclude '/var/lib/alsa' \ + --exclude '/var/lib/tor' \ + --exclude '/data/homes/*' \ + --exclude '/data/music/*' \ + --exclude '/data/pictures/*' \ + --exclude '/data/programming/*' \ + --exclude '/data/torrents/*' \ + --exclude '/home/*/.ssh/control*' \ + --exclude '*/.git/*' \ + --exclude '*/.stack-work/*' \ + --exclude '*/lock' \ + \ + ::'{hostname}-{now}' \ + /etc \ + /var \ + /home/ninewise/dotfiles \ + /home/ninewise/.gnupg \ + /home/ninewise/.password-store \ + /home/ninewise/.ssh \ + /home/ninewise/.xmonad/src/ \ + /home/ninewise/.yash_history \ + /data + +backup_exit=$? + +info "Pruning repository" + +# Use the `prune` subcommand to maintain 7 daily, 4 weekly and 6 monthly +# archives of THIS machine. The '{hostname}-' prefix is very important to +# limit prune's operation to this machine's archives and not apply to +# other machines' archives also: + +borg prune \ + --list \ + --prefix '{hostname}-' \ + --show-rc \ + --keep-daily 7 \ + --keep-weekly 4 \ + --keep-monthly 6 + +prune_exit=$? + +global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit )) + +if [ ${global_exit} -eq 0 ]; then + info "Backup and Prune finished successfully" +elif [ ${global_exit} -eq 1 ]; then + info "Backup and/or Prune finished with warnings" +else + info "Backup and/or Prune finished with errors" +fi + +exit ${global_exit}