configuration/local/bin/backup

96 lines
3.0 KiB
Plaintext
Raw Normal View History

2021-05-07 00:01:51 +02:00
#!/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' \
2021-05-18 23:50:05 +02:00
--exclude '/etc/sudoers' \
--exclude '/etc/securetty' \
--exclude '/etc/wpa_supplicant/wpa_supplicant.conf' \
--exclude '/etc/sudoers.dist' \
--exclude '/etc/kernel.d/post-install/50-grub' \
--exclude '/etc/kernel.d/post-remove/50-grub' \
--exclude '/etc/.pwd.lock' \
--exclude '/etc/gshadow-' \
--exclude '/etc/passwd-' \
--exclude '/etc/shadow-' \
--exclude '/etc/shadow' \
--exclude '/etc/gshadow' \
2021-05-07 00:01:51 +02:00
--exclude '/var/tmp/*' \
--exclude '/var/db/*' \
--exclude '/var/cache' \
--exclude '/var/lib/alsa' \
--exclude '/var/lib/tor' \
2021-05-18 23:50:05 +02:00
--exclude '/var/lib/random-seed' \
--exclude '/var/log/tallylog' \
--exclude '/var/log/btmp' \
--exclude '/var/log/dmesg.log' \
--exclude '/var/log/faillog' \
2021-05-07 00:01:51 +02:00
--exclude '/data/homes/*' \
2021-05-18 23:50:05 +02:00
--exclude '/data/mail/*/.uidvalidity' \
2021-05-07 00:01:51 +02:00
--exclude '/data/music/*' \
--exclude '/data/pictures/*' \
--exclude '/data/programming/*' \
--exclude '/data/torrents/*' \
--exclude '/home/*/.ssh/control*' \
2021-05-18 23:50:05 +02:00
--exclude '/home/*/services/*/supervise' \
2021-05-07 00:01:51 +02:00
--exclude '*/.git/*' \
--exclude '*/.stack-work/*' \
--exclude '*/lock' \
2021-05-18 23:50:05 +02:00
--exclude '*/.mbsyncstate*' \
2021-05-07 00:01:51 +02:00
\
::'{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}