From ddd28e45d507665ffd89b35e8c759b6add7686a6 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Wed, 19 Jun 2019 18:26:54 -0400 Subject: add some commands to the live system --- src/samizdat-daily-snapshot-root | 55 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 src/samizdat-daily-snapshot-root (limited to 'src/samizdat-daily-snapshot-root') diff --git a/src/samizdat-daily-snapshot-root b/src/samizdat-daily-snapshot-root new file mode 100755 index 0000000..c57524c --- /dev/null +++ b/src/samizdat-daily-snapshot-root @@ -0,0 +1,55 @@ +#/bin/sh +[ "$(id -u)" = 0 ] || exec sudo "$0" "$@" || exit + +is_subvol() +{ + btrfs subvolume show "$1" >/dev/null 2>&1 +} + +btrfs_subvolumes() +{ + btrfs subvolume list -a -t "${1:-/}" | awk '{print $4}' | sed -Ene 's?^(/)\?root/?/?p' +} + +snapit() +{ + local dev mnt target + + mnt=$(mktemp -d /tmp/mnt.XXXXXX) || return + src=$mnt/$1/ + target=$mnt/${2:-daily/}${1%/}~$(date -I) + dev=$(btrfs fi sh / | sed -ne 's/.* path //p' | tail -n1) || return + + mount "$dev" -o subvol=/ "$mnt" + if [ -e "$target" ] + then + : + else + mkdir -p "$(dirname "$target")" + btrfs subvolume snapshot -r "$src" "$target" + fi + umount "$mnt" + rmdir "$mnt" +} + +do_not_snap() +{ + case "${1#/root/}" in + /var/cache/apt/archives|/home/*/.cache|/home/*/src/fsmgr/_build|/home/*/.stack|/home/*/.rustup) + true + ;; + *) + false + ;; + esac +} + +snapit /root + +btrfs_subvolumes | while read f +do + if is_subvol "$f" + then + do_not_snap "$f" || snapit /root/"${f#/}" + fi +done -- cgit v1.2.3