From c928e4767ac93cd91b01c2c6c94fdbdafac99336 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Fri, 31 Jan 2025 22:22:39 +0300 Subject: [PATCH 1/2] refactoring... Signed-off-by: Alex A. Naanou --- Archive/snapshot.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Archive/snapshot.sh b/Archive/snapshot.sh index 1aabc678..17e57cc8 100755 --- a/Archive/snapshot.sh +++ b/Archive/snapshot.sh @@ -1,5 +1,7 @@ #!/usr/bin/bash +# XXX this should run in script dir (not cwd)... + # XXX need: # - protocol (command) to create archive root # - protocol to create snapshots @@ -30,13 +32,12 @@ if ! [ -e ./media ] ; then # convert ./media to a subvolume... elif [ "$(stat --format=%i ./media)" == 256 ] ; then - btrfs subvolume create ./media_subvolume - #mv ./media/{,.}* ./media_subvolume/ + mkdir bak + mv media bak/ + btrfs subvolume create ./media cp --archive --one-file-system --reflink=always \ - ./media/{,.}* \ - ./media_subvolume/ - mv ./media{,.bak} - mv ./media{_subvolume,} + ./bak/media/{,.}* \ + ./media/ fi mkdir -p ./.snapshots From 9fe6678b9521ad33b09ad16feada02b052acddb3 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 1 Feb 2025 20:23:52 +0300 Subject: [PATCH 2/2] refactoring and cleanup... Signed-off-by: Alex A. Naanou --- Archive/snapshot.sh | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/Archive/snapshot.sh b/Archive/snapshot.sh index 17e57cc8..df62e977 100755 --- a/Archive/snapshot.sh +++ b/Archive/snapshot.sh @@ -1,9 +1,12 @@ #!/usr/bin/bash -# XXX this should run in script dir (not cwd)... - # XXX need: # - protocol (command) to create archive root +# manually: +# - copy tree +# - run snapshot.sh +# script: +# XXX # - protocol to create snapshots # - sync-flash.sh ??? # - protocol to restore stuff -- simply copy??? @@ -14,6 +17,16 @@ # - a way to maintain a set number of snapshots... # +SNAPSHOT_DIR=.snapshots +SUBVOLUME_DIR=media + + +# run in script dir (not cwd)... +DIR=`dirname "$0"` +if ! [ -z "$DIR" ] ; then + cd "$DIR" +fi + # check if on btrfs filesystem... # XXX also check if btrfs command is available... if ! btrfs filesystem usage . > /dev/null ; then @@ -26,29 +39,32 @@ fi # create ./media... # XXX check if not a directory... -if ! [ -e ./media ] ; then - btrfs subvolume create ./media +if ! [ -e "$SUBVOLUME_DIR" ] ; then + btrfs subvolume create "$SUBVOLUME_DIR" # XXX build tree -- ImageGrid # convert ./media to a subvolume... -elif [ "$(stat --format=%i ./media)" == 256 ] ; then +elif [ "$(stat --format=%i "$SUBVOLUME_DIR")" == 256 ] ; then mkdir bak - mv media bak/ - btrfs subvolume create ./media + mv "$SUBVOLUME_DIR" bak/ + btrfs subvolume create "$SUBVOLUME_DIR" cp --archive --one-file-system --reflink=always \ - ./bak/media/{,.}* \ - ./media/ + ./bak/"$SUBVOLUME_DIR"/{,.}* \ + "$SUBVOLUME_DIR"/ fi -mkdir -p ./.snapshots +mkdir -p "$SNAPSHOT_DIR" # XXX should this be more human readable??? # ...a date + number maybe??? SNAPSHOT=$(( - $( ls .snapshots \ + $( ls "$SNAPSHOT_DIR" \ | sort -n \ | tail -n 1 ) \ + 1 )) -btrfs subvolume snapshot -r ./media .snapshots/${SNAPSHOT} +btrfs subvolume snapshot -r "$SUBVOLUME_DIR" "${SNAPSHOT_DIR}/${SNAPSHOT}" + + +# vim:set nowrap nospell :