wok view btrfs-progs/stuff/btrfs-snapshot @ rev 13685

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