diff options
Diffstat (limited to 'arch-system/backup-sudo')
-rwxr-xr-x | arch-system/backup-sudo | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/arch-system/backup-sudo b/arch-system/backup-sudo new file mode 100755 index 0000000..90590e0 --- /dev/null +++ b/arch-system/backup-sudo @@ -0,0 +1,40 @@ +#!/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" + # small race, but shouldn't matter + if ! btrfs subvolume show "$3" > /dev/null 2>&1; then + echo "Not a btrfs subvolume." >&2 + exit 3 + fi + touch -c -- "$3" + btrfs subvolume snapshot -r -- "$3" "$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 -df /backup + ;; + *) + echo "No command specified." >&2 + exit 1 + ;; +esac |