Last active
October 21, 2015 07:47
-
-
Save jaquer/0887ba5f3b6863cd3dbf to your computer and use it in GitHub Desktop.
Root FS snapshotting script using BTRFS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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