wok annotate btrfs-progs/stuff/btrfs-snapshot @ rev 15089

ploticus: update bdeps
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Aug 13 21:17:32 2013 +0000 (2013-08-13)
parents 90f1623aac5e
children
rev   line source
pascal@13508 1 #!/bin/sh
pascal@13508 2
pascal@13572 3 # Keep last 30 daily snapshots with crontab
pascal@13685 4 # Note: do not create 2 snapshots simultaneously (break btrfs mountage)
pascal@13572 5 #0 * * * * /usr/bin/btrfs-snapshot 5 -hourly
pascal@13685 6 #1 0 * * * /usr/bin/btrfs-snapshot 30 -daily
pascal@13685 7 #2 0 1 * * /usr/bin/btrfs-snapshot 12 -monthly
pascal@13685 8 #3 0 1 1 * /usr/bin/btrfs-snapshot 99 -yearly
pascal@13508 9
pascal@13508 10 btrfs_list()
pascal@13508 11 {
pascal@13508 12 awk '/ btrfs / { if (fs[$1] == "") { fs[$1] = $2; print $2 }}' \
pascal@13508 13 < /proc/mounts
pascal@13508 14 }
pascal@13508 15
pascal@13508 16 which btrfs > /dev/null && for root in $(btrfs_list) ; do
pascal@13572 17 dir=${root%/}/.snapshots$2
pascal@13508 18 [ -d $dir ] || mkdir $dir
pascal@13508 19 cd $dir
pascal@13508 20 i=0
pascal@13508 21 for s in $(ls -r); do
pascal@13508 22 [ $((i++)) -ge ${1:-10} ] && btrfs subvolume delete $s
pascal@13508 23 done
pascal@13508 24 btrfs subvolume snapshot -r / $(date +%Y%m%d%H%M%S)
pascal@13508 25 done