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

Up jabberd2 (2.2.16)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Nov 04 18:18:29 2012 +0100 (2012-11-04)
parents 09fb684d4984
children 9584476eeb17
rev   line source
pascal@13508 1 #!/bin/sh
pascal@13508 2
pascal@13572 3 # Keep last 30 daily snapshots with crontab
pascal@13572 4 #0 * * * * /usr/bin/btrfs-snapshot 5 -hourly
pascal@13572 5 #0 0 * * * /usr/bin/btrfs-snapshot 30 -daily
pascal@13572 6 #0 0 1 * * /usr/bin/btrfs-snapshot 12 -monthly
pascal@13572 7 #0 0 1 1 * /usr/bin/btrfs-snapshot 99 -yearly
pascal@13508 8
pascal@13508 9 btrfs_list()
pascal@13508 10 {
pascal@13508 11 awk '/ btrfs / { if (fs[$1] == "") { fs[$1] = $2; print $2 }}' \
pascal@13508 12 < /proc/mounts
pascal@13508 13 }
pascal@13508 14
pascal@13508 15 which btrfs > /dev/null && for root in $(btrfs_list) ; do
pascal@13572 16 dir=${root%/}/.snapshots$2
pascal@13508 17 [ -d $dir ] || mkdir $dir
pascal@13508 18 cd $dir
pascal@13508 19 i=0
pascal@13508 20 for s in $(ls -r); do
pascal@13508 21 [ $((i++)) -ge ${1:-10} ] && btrfs subvolume delete $s
pascal@13508 22 done
pascal@13508 23 btrfs subvolume snapshot -r / $(date +%Y%m%d%H%M%S)
pascal@13508 24 done