wok diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/btrfs-progs/stuff/btrfs-snapshot	Sun Oct 14 18:03:37 2012 +0200
     1.3 @@ -0,0 +1,21 @@
     1.4 +#!/bin/sh
     1.5 +
     1.6 +# Keep last 30 daily snapshot with crontab
     1.7 +#0 0 * * * /usr/bin/btrfs-snapshot 30
     1.8 +
     1.9 +btrfs_list()
    1.10 +{
    1.11 +	awk '/ btrfs / { if (fs[$1] == "") { fs[$1] = $2; print $2 }}' \
    1.12 +		< /proc/mounts
    1.13 +}
    1.14 +
    1.15 +which btrfs > /dev/null && for root in $(btrfs_list) ; do
    1.16 +	dir=${root%/}/.snapshots
    1.17 +	[ -d $dir ] || mkdir $dir
    1.18 +	cd $dir
    1.19 +	i=0
    1.20 +	for s in $(ls -r); do
    1.21 +		[ $((i++)) -ge ${1:-10} ] && btrfs subvolume delete $s
    1.22 +	done
    1.23 +	btrfs subvolume snapshot -r / $(date +%Y%m%d%H%M%S)
    1.24 +done