3 # Copyright 2011 by Jan Vales <jan@jvales.net> (Someone <someone@somenet.org>)
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, version 3 of the License.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # Take BTRFS snapshots
20 # 0 * * * * /root/somescripts/btrfs/snapshot.sh &> /dev/null
21 # This script will generate: current_$vol.snp/.txt + last_$vol.snp/.txt and date_$date_$vol.snp/.txt
23 # Set volumes to autosnap
24 SNAPLIST="root home homeroot"
26 # Timestamp of creation.
27 STARTTS="`date +'%Y-%m-%d--%H-%M'`"
31 mount /mnt/btrfs &> /dev/null
34 for vol in $SNAPLIST; do
35 if [ -e "ahour_curr_${vol}.snp" -a -e "ahour_curr_${vol}.txt" ]; then
36 if [ -e "ahour_last_${vol}.snp" -a -e "ahour_last_${vol}.txt" ]; then
37 echo "Autosnap: Moving ahour_last_${vol}.snp to: `cat ahour_last_${vol}.txt`"
38 mv "ahour_last_${vol}.snp" "`cat ahour_last_${vol}.txt`"
40 echo "Autosnap: Moving ahour_curr_${vol}.snp to: ahour_last_${vol}.snp"
41 mv "ahour_curr_${vol}.snp" "ahour_last_${vol}.snp"
42 mv "ahour_curr_${vol}.txt" "ahour_last_${vol}.txt"
44 echo "Autosnap: Snapshotting ahour_curr_${vol}.snp (${STARTTS})"
45 echo "aadate_${STARTTS}_${vol}.snap" > ahour_curr_${vol}.txt
46 btrfs subvolume snapshot "${vol}" "ahour_curr_${vol}.snp"
47 touch -m -a "ahour_curr_${vol}.snp"
52 umount /mnt/btrfs &> /dev/null || echo "Failed to unmount"