I've already done something similar. I take hourly, daily, weekly, and monthly
snapshots of my /home subvolume. Here's the script I've created for this:
#! /bin/bash
if [ "$#" -ne 2 ]; then
echo Usage $0 SNAPSHOT_PREFIX NUM_SNAPSHOTS
exit 1
fi
SNAPS=/var/lib/btrfs-root/__snapshot/home
btrfs subvolume snapshot -r /home $SNAPS/$1_$(date +%F_%T.%N)
num_snaps=$(ls -1d $SNAPS/$1_* | sort | wc -l)
if [ "$num_snaps" -gt "$2" ]; then
let over=$num_snaps-$2
ls -1d $SNAPS/$1_* | head -n $over | while read s; do
btrfs subvolume delete $s
done
fi
Here's my crontab:
0 * * * * /usr/local/bin/snapshot hourly 6
0 0 * * * /usr/local/bin/snapshot daily 7
0 0 * * 0 /usr/local/bin/snapshot weekly 4
--
-=[dave]=-
Entropy isn't what it used to be.
Attachment:
pgpwJtt6OIlFn.pgp
Description: PGP signature
