wok-current 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 9000cde8e23a
children ba3b4a174a88
files btrfs-progs/receipt btrfs-progs/stuff/btrfs-snapshot
line diff
     1.1 --- a/btrfs-progs/receipt	Sun Oct 14 12:11:18 2012 +0200
     1.2 +++ b/btrfs-progs/receipt	Sun Oct 14 18:03:37 2012 +0200
     1.3 @@ -27,6 +27,7 @@
     1.4  {
     1.5  	mkdir -p $fs/usr
     1.6  	cp -a $install/usr/bin $fs/usr
     1.7 +	cp -a $stuff/btrfs-snapshot $fs/usr/bin
     1.8  	# Split mkfs --> btrfs-mkfs
     1.9  	rm $fs/usr/bin/mkfs.btrfs
    1.10  }
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/btrfs-progs/stuff/btrfs-snapshot	Sun Oct 14 18:03:37 2012 +0200
     2.3 @@ -0,0 +1,21 @@
     2.4 +#!/bin/sh
     2.5 +
     2.6 +# Keep last 30 daily snapshot with crontab
     2.7 +#0 0 * * * /usr/bin/btrfs-snapshot 30
     2.8 +
     2.9 +btrfs_list()
    2.10 +{
    2.11 +	awk '/ btrfs / { if (fs[$1] == "") { fs[$1] = $2; print $2 }}' \
    2.12 +		< /proc/mounts
    2.13 +}
    2.14 +
    2.15 +which btrfs > /dev/null && for root in $(btrfs_list) ; do
    2.16 +	dir=${root%/}/.snapshots
    2.17 +	[ -d $dir ] || mkdir $dir
    2.18 +	cd $dir
    2.19 +	i=0
    2.20 +	for s in $(ls -r); do
    2.21 +		[ $((i++)) -ge ${1:-10} ] && btrfs subvolume delete $s
    2.22 +	done
    2.23 +	btrfs subvolume snapshot -r / $(date +%Y%m%d%H%M%S)
    2.24 +done