refactoring and cleanup...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2025-02-01 20:23:52 +03:00
parent c928e4767a
commit 9fe6678b95

View File

@ -1,9 +1,12 @@
#!/usr/bin/bash #!/usr/bin/bash
# XXX this should run in script dir (not cwd)...
# XXX need: # XXX need:
# - protocol (command) to create archive root # - protocol (command) to create archive root
# manually:
# - copy tree
# - run snapshot.sh
# script:
# XXX
# - protocol to create snapshots # - protocol to create snapshots
# - sync-flash.sh ??? # - sync-flash.sh ???
# - protocol to restore stuff -- simply copy??? # - protocol to restore stuff -- simply copy???
@ -14,6 +17,16 @@
# - a way to maintain a set number of snapshots... # - 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... # check if on btrfs filesystem...
# XXX also check if btrfs command is available... # XXX also check if btrfs command is available...
if ! btrfs filesystem usage . > /dev/null ; then if ! btrfs filesystem usage . > /dev/null ; then
@ -26,29 +39,32 @@ fi
# create ./media... # create ./media...
# XXX check if not a directory... # XXX check if not a directory...
if ! [ -e ./media ] ; then if ! [ -e "$SUBVOLUME_DIR" ] ; then
btrfs subvolume create ./media btrfs subvolume create "$SUBVOLUME_DIR"
# XXX build tree -- ImageGrid # XXX build tree -- ImageGrid
# convert ./media to a subvolume... # convert ./media to a subvolume...
elif [ "$(stat --format=%i ./media)" == 256 ] ; then elif [ "$(stat --format=%i "$SUBVOLUME_DIR")" == 256 ] ; then
mkdir bak mkdir bak
mv media bak/ mv "$SUBVOLUME_DIR" bak/
btrfs subvolume create ./media btrfs subvolume create "$SUBVOLUME_DIR"
cp --archive --one-file-system --reflink=always \ cp --archive --one-file-system --reflink=always \
./bak/media/{,.}* \ ./bak/"$SUBVOLUME_DIR"/{,.}* \
./media/ "$SUBVOLUME_DIR"/
fi fi
mkdir -p ./.snapshots mkdir -p "$SNAPSHOT_DIR"
# XXX should this be more human readable??? # XXX should this be more human readable???
# ...a date + number maybe??? # ...a date + number maybe???
SNAPSHOT=$(( SNAPSHOT=$((
$( ls .snapshots \ $( ls "$SNAPSHOT_DIR" \
| sort -n \ | sort -n \
| tail -n 1 ) \ | tail -n 1 ) \
+ 1 )) + 1 ))
btrfs subvolume snapshot -r ./media .snapshots/${SNAPSHOT} btrfs subvolume snapshot -r "$SUBVOLUME_DIR" "${SNAPSHOT_DIR}/${SNAPSHOT}"
# vim:set nowrap nospell :