diff options
author | Tharre <tharre3@gmail.com> | 2018-03-27 07:02:36 +0200 |
---|---|---|
committer | Tharre <tharre3@gmail.com> | 2018-03-27 07:17:08 +0200 |
commit | b8a806dfc701118ce1f10d5332093ac1f710d808 (patch) | |
tree | 264129ebbf2db959ffbd4dfa97c6034222b1434c /arch-system/backup-sudo | |
parent | 3cf436534fc2c3886184d7bbf441f45791bdc4a0 (diff) | |
download | pkgbuilds-b8a806dfc701118ce1f10d5332093ac1f710d808.tar.gz pkgbuilds-b8a806dfc701118ce1f10d5332093ac1f710d808.tar.xz pkgbuilds-b8a806dfc701118ce1f10d5332093ac1f710d808.zip |
arch-system: add backup-system package
This implements fully automated, hourly backups of my /home via
borgbackup, btrfs and systemd timers.
Note that `setup_borgbackup`, a related function that is part of my
dotfiles, is needed to setup backups for the first time, as well as a
call to `borg init` with the proper environment variables.
Diffstat (limited to 'arch-system/backup-sudo')
-rwxr-xr-x | arch-system/backup-sudo | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/arch-system/backup-sudo b/arch-system/backup-sudo new file mode 100755 index 0000000..b2694b6 --- /dev/null +++ b/arch-system/backup-sudo @@ -0,0 +1,34 @@ +#!/bin/bash -e + +validate_path() { + # validate path + targetpath=$(realpath -m -- "$1") + if [[ "$targetpath" != /.snapshots/* ]]; then + echo "Invalid path given." >&2 + exit 2 + fi +} + +case "$1" in + snapshot) + validate_path "$2" + btrfs subvolume snapshot -r -- /home "$2" + ;; + delete_snapshot) + validate_path "$2" + btrfs subvolume delete -- "$2" + ;; + mount) + validate_path "$2" + mkdir -p /backup + mount --bind -- "$2" /backup + ;; + cleanup) + umount /backup 2> /dev/null || true + rm -rf /backup + ;; + *) + echo "No command specified." >&2 + exit 1 + ;; +esac |