]> git.somenet.org - root/btrfs.git/blob - snapshot.sh
some changes, added timestamping, ...
[root/btrfs.git] / snapshot.sh
1 #!/bin/bash
2 #
3 # take BTRFS snapshots
4 # 0 * * * * /root/somescripts/btrfs/snapshot.sh &> /dev/null
5 # This script will generate: current_$vol.snp/.txt + last_$vol.snp/.txt and date_$date_$vol.snp/.txt
6 #
7 # Set volumes to autosnap
8 SNAPLIST="root home var homeroot"
9
10 # Timestamp of creation.
11 STARTTS="`date +'%Y-%m-%d--%H-%M'`"
12 CALLPATH="`pwd`"
13
14 echo $STARTTS
15 mount /mnt/btrfs &> /dev/null
16 cd /mnt/btrfs
17
18 for vol in $SNAPLIST; do
19   if [ -e "ahour_curr_${vol}.snp" -a -e "ahour_curr_${vol}.txt" ]; then
20     if [ -e "ahour_last_${vol}.snp" -a -e "ahour_last_${vol}.txt" ]; then
21       echo "Autosnap: Moving ahour_last_${vol}.snp to: `cat ahour_last_${vol}.txt`"
22       mv "ahour_last_${vol}.snp" "`cat ahour_last_${vol}.txt`"
23     fi
24     echo "Autosnap: Moving ahour_curr_${vol}.snp to: ahour_last_${vol}.snp"
25     mv "ahour_curr_${vol}.snp" "ahour_last_${vol}.snp"
26     mv "ahour_curr_${vol}.txt" "ahour_last_${vol}.txt"
27   fi
28   echo "Autosnap: Snapshotting ahour_curr_${vol}.snp (${STARTTS})"
29   echo "aadate_${STARTTS}_${vol}.snap" > ahour_curr_${vol}.txt
30   btrfs subvolume snapshot "${vol}" "ahour_curr_${vol}.snp"
31   touch -m -a "ahour_curr_${vol}.snp"
32 done
33
34 cd $CALLPATH
35 umount /mnt/btrfs &> /dev/null || echo "Failed to unmount"
36