Skip to content

Instantly share code, notes, and snippets.

@jaquer
Last active October 21, 2015 07:47
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 jaquer/0887ba5f3b6863cd3dbf to your computer and use it in GitHub Desktop.
Save jaquer/0887ba5f3b6863cd3dbf to your computer and use it in GitHub Desktop.
Root FS snapshotting script using BTRFS
#!/bin/sh -e
#
# simple rootfs (/) snapshots using BTRFS
# variables
ROOT=/media/root/@
# begin script
if [ $(id --user) != 0 ]; then
echo "script must be run as root"
exit
fi
DATETIME=$(date --iso-8601=seconds)
DEST=${ROOT}-${DATETIME}
LOGFILE=${DEST}.log
btrfs subvolume snapshot -r ${ROOT} ${DEST}
ln --symbolic --force --relative --no-target-directory ${DEST} ${ROOT}-latest
# open log file to add description of changes
nano --tempfile ${LOGFILE}
chmod 0444 ${LOGFILE}
# sync timestamps
touch --reference ${DEST} ${LOGFILE}
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment