]> git.somenet.org - root/btrfs.git/blob - snapshot.sh
moved btrfs scripts out of overall script dir
[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 rw"
9
10 # Timestamp of creation.
11 STARTTS="`date +'%Y-%m-%d--%H-%M'`"
12 CALLPATH="`pwd`"
13
14 mount /mnt/btrfs &> /dev/null
15 cd /mnt/btrfs
16
17 for vol in $SNAPLIST; do
18   if [ -e "ahour_curr_${vol}.snp" -a -e "ahour_curr_${vol}.txt" ]; then
19     if [ -e "ahour_last_${vol}.snp" -a -e "ahour_last_${vol}.txt" ]; then
20       echo "Autosnap: Moving ahour_last_${vol}.snp to: `cat ahour_last_${vol}.txt`"
21       mv "ahour_last_${vol}.snp" "`cat ahour_last_${vol}.txt`"
22     fi
23     echo "Autosnap: Moving ahour_curr_${vol}.snp to: ahour_last_${vol}.snp"
24     mv "ahour_curr_${vol}.snp" "ahour_last_${vol}.snp"
25     mv "ahour_curr_${vol}.txt" "ahour_last_${vol}.txt"
26   fi
27   echo "Autosnap: Snapshotting ahour_curr_${vol}.snp (${STARTTS})"
28   echo "aadate_${STARTTS}_${vol}.snap" > ahour_curr_${vol}.txt
29   btrfs subvolume snapshot "${vol}" "ahour_curr_${vol}.snp"
30   touch -m -a "ahour_curr_${vol}.snp"
31 done
32
33 cd $CALLPATH
34 umount /mnt/btrfs &> /dev/null || echo "Failed to unmount"
35