configuration/local/bin/backup

176 lines
6.1 KiB
Plaintext
Raw Permalink 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"
2021-08-17 21:52:46 +02:00
case "$(hostname)" in
mantle)
borg create \
--verbose \
--filter AME \
--list \
--stats \
--show-rc \
--compression lz4 \
--exclude-caches \
--exclude '/etc/sv/*/supervise' \
--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' \
2024-07-24 08:35:41 +02:00
--exclude '/etc/mumble/mumble-server.ini' \
2021-08-17 21:52:46 +02:00
--exclude '/etc/.pwd.lock' \
--exclude '/etc/gshadow-' \
--exclude '/etc/passwd-' \
--exclude '/etc/shadow-' \
--exclude '/etc/shadow' \
2021-09-03 07:45:27 +02:00
--exclude '/etc/ssh/ssh_*_key' \
2024-07-24 08:35:41 +02:00
--exclude '/etc/tcsd.conf' \
2021-08-17 21:52:46 +02:00
--exclude '/etc/gshadow' \
--exclude '/var/tmp/*' \
--exclude '/var/db/*' \
--exclude '/var/cache' \
--exclude '/var/lib/alsa' \
2024-07-24 08:35:41 +02:00
--exclude '/var/lib/dkms/mok.key' \
2021-08-17 21:52:46 +02:00
--exclude '/var/lib/tor' \
--exclude '/var/lib/random-seed' \
2022-07-12 11:25:46 +02:00
--exclude '/var/lib/seedrng' \
2024-07-24 08:35:41 +02:00
--exclude '/var/lib/tpm' \
2021-08-17 21:52:46 +02:00
--exclude '/var/log/tallylog' \
--exclude '/var/log/btmp' \
--exclude '/var/log/dmesg.log' \
--exclude '/var/log/faillog' \
--exclude '/data/homes/*' \
--exclude '/data/mail/*/.uidvalidity' \
--exclude '/data/music/*' \
--exclude '/data/pictures/*' \
--exclude '/data/torrents/*' \
--exclude '/home/*/.ssh/control*' \
--exclude '/home/*/services/*/supervise' \
--exclude '/home/*/.config/transmission*/resume' \
2021-08-17 21:52:46 +02:00
--exclude '*/.git/*' \
--exclude '*/.stack-work/*' \
--exclude '*/lock' \
--exclude '*/.mbsyncstate*' \
--exclude '*/target/*' \
--exclude '*/build/*' \
--exclude '/data/programming/void-packages/*' \
--exclude '/data/programming/SP-Flash-Tool-src/*' \
--exclude '/data/programming/obs-v4l2sink/*' \
--exclude '/data/programming/obs-studio/*' \
\
::'{hostname}-{now}' \
/etc \
/var \
/home/ninewise/dotfiles \
/home/ninewise/.gnupg \
/home/ninewise/.password-store \
/home/ninewise/.ssh \
/home/ninewise/.zsh_history \
2021-08-17 21:52:46 +02:00
/data ;;
abysm)
borg create \
--verbose \
--filter AME \
--list \
--stats \
--show-rc \
--compression lz4 \
--exclude-caches \
2021-08-30 14:36:17 +02:00
--exclude '/etc/dhcpcd.secret' \
2021-09-06 13:55:13 +02:00
--exclude '/etc/dracut.conf.d/*' \
2021-08-30 14:36:17 +02:00
--exclude '/etc/iwd/main.conf' \
2021-08-17 21:52:46 +02:00
--exclude '/etc/sv/*/supervise' \
2021-08-30 14:36:17 +02:00
--exclude '/etc/sv/*/log/run' \
2021-08-17 21:52:46 +02:00
--exclude '/etc/sudoers' \
--exclude '/etc/securetty' \
--exclude '/etc/wpa_supplicant/wpa_supplicant.conf' \
2021-08-30 14:36:17 +02:00
--exclude '/etc/sv/wpa_supplicant/conf' \
2021-09-06 13:55:13 +02:00
--exclude '/etc/sudoers.*' \
2021-08-17 21:52:46 +02:00
--exclude '/etc/kernel.d/post-install/50-grub' \
--exclude '/etc/kernel.d/post-remove/50-grub' \
--exclude '/etc/gshadow-' \
--exclude '/etc/gshadow' \
--exclude '/etc/passwd-' \
--exclude '/etc/shadow-' \
--exclude '/etc/shadow' \
2021-08-30 14:36:17 +02:00
--exclude '/etc/ssh/ssh_host_*_key' \
--exclude '/etc/udev/rules.d/*' \
--exclude '/etc/X11/xorg.conf.d/*' \
2021-08-17 21:52:46 +02:00
--exclude '/var/tmp/*' \
--exclude '/var/db/*' \
--exclude '/var/cache' \
--exclude '/var/lib/alsa' \
2021-08-30 14:36:17 +02:00
--exclude '/var/lib/ead' \
--exclude '/var/lib/iwd' \
2021-08-17 21:52:46 +02:00
--exclude '/var/lib/tor' \
--exclude '/var/lib/random-seed' \
--exclude '/var/log/tallylog' \
--exclude '/var/log/btmp' \
--exclude '/var/log/dmesg.log' \
--exclude '/var/log/faillog' \
2021-08-30 14:36:17 +02:00
--exclude '/var/log/lastlog' \
--exclude '/home/*/.ssh/control*' \
2021-08-17 21:52:46 +02:00
--exclude '/home/*/services/*/supervise' \
--exclude '/home/*/dotfiles' \
--exclude '/home/*/.local/share' \
--exclude '/home/*/.local/lib' \
--exclude '/home/*/.cache' \
--exclude '/home/*/.dbus' \
--exclude '/home/*/.hoogle' \
--exclude '/home/*/.config/microbrowser/data' \
--exclude '/home/*/.config/googlebrowser/data' \
2021-08-17 21:52:46 +02:00
--exclude '*/.git/*' \
--exclude '*/.stack-work/*' \
--exclude '*/lock' \
--exclude '*.lock' \
--exclude '*/.mbsyncstate*' \
--exclude '*/target/*' \
--exclude '*/build/*' \
::'{hostname}-{now}' \
/etc \
/var \
/home/noctua/.password-store \
/home/noctua/.zsh_history \
/home/noctua/.ssh \
2021-08-17 21:52:46 +02:00
/home/noctua/ ;;
esac
2021-05-07 00:01:51 +02:00
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 \
2024-07-24 08:35:41 +02:00
--glob-archives '{hostname}-*' \
2021-05-07 00:01:51 +02:00
--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}