Skip to content

Instantly share code, notes, and snippets.

@ed-davies
Created April 20, 2023 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ed-davies/eb866c85b7beb7baf0ed511551410eed to your computer and use it in GitHub Desktop.
Save ed-davies/eb866c85b7beb7baf0ed511551410eed to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
STAMP=$(date "+%Y-%m-%dT%H:%M:%S")
DEST=/media/ed/hitachi
MACHINE=$(uname -n)
TARGET=$DEST/$MACHINE
[ -d $TARGET ] || (
mkdir $TARGET
mkdir $TARGET/0
ln -s ../0 $TARGET/current
)
[ -L $TARGET/current ] || (
echo Target directory $TARGET/current doesn\'t exist or isn\'t a symlink
false
)
for DIR in home etc usr/local
do
mkdir -p $TARGET/incomplete-$STAMP/$DIR
rsync -axv --link-dest=$TARGET/current/$DIR/ /$DIR/ $TARGET/incomplete-$STAMP/$DIR/
done
mv $TARGET/incomplete-$STAMP $TARGET/back-$STAMP
rm -f $TARGET/current
ln -s back-$STAMP $TARGET/current
ls -l $TARGET
df -h $DEST
umount $DEST
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment