From f6f719c11e5e0ce8d8dbabdd612ce636fa6f9b91 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Tue, 28 Jan 2025 03:17:32 +0300 Subject: [PATCH] added conversion to subvolume... Signed-off-by: Alex A. Naanou --- Archive/snapshot.sh | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/Archive/snapshot.sh b/Archive/snapshot.sh index 8b5ce6ac..9b1bf570 100755 --- a/Archive/snapshot.sh +++ b/Archive/snapshot.sh @@ -1,21 +1,46 @@ #!/usr/bin/bash +# XXX need: +# - protocol to restore stuff -- simply copy??? +# - protocol to fully delete something -- i.e. delete snapshots??? +# - a way to list deleted files +# - a way to list available file versions +# - a way to restore specicifc file(s) +# - a way to maintain a set number of snapshots... +# + +# check if on btrfs filesystem... +# XXX also check if btrfs command is available... +if ! btrfs filesystem usage . > /dev/null ; then + exit +fi + + +# create ./media... if ! [ -e ./media ] ; then btrfs subvolume create ./media # XXX build tree -- ImageGrid -fi -if ! [ -e ./.snapshots ] ; then - mkdir ./.snapshots -fi -#DATE=`date +%Y%m%d-%H%M%S` +# convert ./media to a subvolume... +elif [ "$(stat --format=%i ./media)" == 256 ] ; then + btrfs subvolume create ./media_subvolume + #mv ./media/{,.}* ./media_subvolume/ + cp --archive --one-file-system --reflink=always \ + ./media/{,.}* \ + ./media_subvolume/ + mv ./media{,.bak} + mv ./media{_subvolume,} +fi +mkdir -p ./.snapshots + +# XXX should this be more human readable??? +# ...a date + number maybe??? SNAPSHOT=$(( $( ls .snapshots \ | sort -n \ | tail -n 1 ) \ + 1 )) - btrfs subvolume snapshot -r ./media .snapshots/${SNAPSHOT}