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
7 # Set volumes to autosnap
8 SNAPLIST="root home rw"
10 # Timestamp of creation.
11 STARTTS="`date +'%Y-%m-%d--%H-%M'`"
14 mount /mnt/btrfs &> /dev/null
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`"
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"
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"
34 umount /mnt/btrfs &> /dev/null || echo "Failed to unmount"