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

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