Skip to content

Instantly share code, notes, and snippets.

@maakuth
Created August 20, 2013 07:18
Show Gist options
  • Save maakuth/6278078 to your computer and use it in GitHub Desktop.
Save maakuth/6278078 to your computer and use it in GitHub Desktop.
Neat way to getting consistent backups of stuff by utilizing LVM snapshots. In my setup /backuptarget is an USB hard drive, but it could be sshfs, smb or nfs share just as well.
#!/bin/sh
. /etc/environment
lvcreate -l90%FREE -s -n rootsnap /dev/host/root
#XFS specific: Mounting ignoring uuid because the original volume has same uuid
mount -o ro,nouuid /dev/host/rootsnap /mnt/rootsnap
mount /backuptarget
#Purge history
rdiff-backup --remove-older-than 1Y /backuptarget/stuff
#Actual backup
rdiff-backup --exclude /mnt/rootsnap/stuff/NotInNeedOfBackingUp /mnt/rootsnap/stuff /backuptarget/stuff
umount /backuptarget
umount /mnt/rootsnap
lvremove -f /dev/host/rootsnap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment