Skip to content

Instantly share code, notes, and snippets.

@Finkregh
Created September 19, 2013 09:35
Show Gist options
  • Save Finkregh/6621196 to your computer and use it in GitHub Desktop.
Save Finkregh/6621196 to your computer and use it in GitHub Desktop.
# Reverse the order of all intervals from /etc/rsnapshot.conf
#interval hourly 3
#interval daily 7
#interval weekly 4
##interval monthly 3
#
# all single commands below should be possible to be scripted within a bash loop
# by defining a function called interval and a process afterwards..
# to get all defined intervals from /etc/rsnapshot you can use grep
## grep ^interval /etc/rsnapshot.conf
#
# change to the backup directory
cd /backup
# Create an directory containing the current snapshots (hardlink-based)
mkdir old
mv daily.* old
mv weekly.* old
mv hourly.* old
# Remove old Ext2/3/4 information
rm ext2_saved/image
btrfs subvolume delete ext2_saved/
# Create the oldes subvolume first
# copy the data to this volume (hopefully this won't use to much space)
# worst case is that we need the complete size of old/weekly.3 as additional harddisk-space
# afterwards delete the old directory
btrfs subvolume create weekly.3
/usr/bin/rsync -aAXpvix --log-file=/backup/rsync.log --numeric-ids --inplace old/weekly.3/ weekly.3/
# an alternative is to make a snapshot of the current volume like this
# This safes more diskspace
btrfs subvolume snapshot . weekly.3
mv weekly.3/old/weekly.3/* weekly.3
rm -rf weekly.3/old
# No copy the oldest snapshot to a newer one and do a syncronisation of the changes again
# afterwards delete the old directory
# do this until we reach the most recent snapshot (hourly.0)
btrfs subvolume snapshot weekly.3 weekly.2
/usr/bin/rsync -aAXpvix --delete --log-file=/backup/rsync.log --numeric-ids --inplace old/weekly.2/ weekly.2/
btrfs subvolume snapshot weekly.2 weekly.1
/usr/bin/rsync -aAXpvix --delete --log-file=/backup/rsync.log --numeric-ids --inplace old/weekly.1/ weekly.1/
btrfs subvolume snapshot weekly.1 weekly.0
/usr/bin/rsync -aAXpvix --delete --log-file=/backup/rsync.log --numeric-ids --inplace old/weekly.0/ weekly.0/
btrfs subvolume snapshot weekly.0 daily.6
/usr/bin/rsync -aAXpvix --delete --log-file=/backup/rsync.log --numeric-ids --inplace old/daily.6/ daily.6/
btrfs subvolume snapshot daily.6 daily.5
/usr/bin/rsync -aAXpvix --delete --log-file=/backup/rsync.log --numeric-ids --inplace old/daily.5/ daily.5/
btrfs subvolume snapshot daily.5 daily.4
/usr/bin/rsync -aAXpvix --delete --log-file=/backup/rsync.log --numeric-ids --inplace old/daily.4/ daily.4/
btrfs subvolume snapshot daily.4 daily.3
/usr/bin/rsync -aAXpvix --delete --log-file=/backup/rsync.log --numeric-ids --inplace old/daily.3/ daily.3/
btrfs subvolume snapshot daily.3 daily.2
/usr/bin/rsync -aAXpvix --delete --log-file=/backup/rsync.log --numeric-ids --inplace old/daily.2/ daily.2/
btrfs subvolume snapshot daily.2 daily.1
/usr/bin/rsync -aAXpvix --delete --log-file=/backup/rsync.log --numeric-ids --inplace old/daily.1/ daily.1/
btrfs subvolume snapshot daily.1 daily.0
/usr/bin/rsync -aAXpvix --delete --log-file=/backup/rsync.log --numeric-ids --inplace old/daily.0/ daily.0/
btrfs subvolume snapshot daily.0 hourly.3
/usr/bin/rsync -aAXpvix --delete --log-file=/backup/rsync.log --numeric-ids --inplace old/hourly.3/ hourly.3/
btrfs subvolume snapshot hourly.3 hourly.2
/usr/bin/rsync -aAXpvix --delete --log-file=/backup/rsync.log --numeric-ids --inplace old/hourly.2/ hourly.2/
btrfs subvolume snapshot hourly.2 hourly.1
/usr/bin/rsync -aAXpvix --delete --log-file=/backup/rsync.log --numeric-ids --inplace old/hourly.1/ hourly.1/
btrfs subvolume snapshot hourly.1 hourly.0
/usr/bin/rsync -aAXpvix --delete --log-file=/backup/rsync.log --numeric-ids --inplace old/hourly.0/ hourly.0/
# We delete the old snapshots at the end. Else rsync will recognize a change of the modification time and
# will touch every file in the snapshots. Therefore the sync process would take longer than it would be necessary.
rm -rf old
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment