Currently I’m doing regular backups from my primary harddisk to my backup-disk using rsnapshots. Due to the fact I have a lot of files generating all needed hardlinks takes quite a long time. To speed up this process it sounded to me like a good idea to switch to btrfs that provides snapshots out of the box.
I found this article HOWTO convert EXT4 partition to Btrfs in Fedora 13 without losing data very helpful for this project.
Using btrfs snapshots instead of cp -al has two major advantages. First of all creating a snapshot is much faster than using hardlinks. and the second advantage is, that meta-information about the file will be preserved (ownership, access and modification-time and also file-attributes). When using hardlinks this information will have the state of the most recent backup-process (also for older backups). Last but not least, if you use a new version of btrfs you can also lock the snapshots down to be read-only.
- crypted harddisk using luks and dmcrypt that is available as /dev/mapper/backup-crypt after being decrypted
- ext4 filesystem on this harddisk (fstab)
# /etc/fstab: static file system information. /dev/sdb1 /boot ext3 defaults,noatime 0 2 /dev/mapper/root_crypt / btrfs defaults,noatime 0 1 /dev/mapper/media /srv/media ext4 defaults,noatime 0 0 /dev/mapper/backup_crypt /backup ext4 defaults,noatime 0 0
- permanently mounted on /backup
- Setup of rsnapshot cron-job
# This is a sample cron file for rsnapshot. # The values used correspond to the examples in /etc/rsnapshot.conf. # There you can also set the backup points and many other things. # # To activate this cron file you have to uncomment the lines below. # Feel free to adapt it to your needs. 0 */8 * * * root /usr/bin/rsnapshot hourly 30 3 * * * root /usr/bin/rsnapshot daily 0 3 * * 1 root /usr/bin/rsnapshot weekly 30 2 1 * * root /usr/bin/rsnapshot monthly
- Setup of rsnapshot
- Deactivate rsnapshots for a while
- Convert the existing backup-volume to btrfs
unmount /backup btrfs-convert /dev/mapper/backup_crypt
This process can take quite a while. So you have some time to go and drink a coffee or make some sports.
- Change the setup of fstab
# /etc/fstab: static file system information. /dev/sdb1 /boot ext3 defaults,noatime 0 2 /dev/mapper/root_crypt / btrfs defaults,noatime 0 1 /dev/mapper/media /srv/media ext4 defaults,noatime 0 0 /dev/mapper/backup_crypt /backup btrfs defaults,noatime 0 0
- You need two additional scripts (rsnapshot_plug_cp_btrfs, rsnapshot_plug_rm_btrfs)
copy these files to /backup and chmod 755 to them 🙂
- These files need to replace the programs specified with cmd_cp and cmd_rm. So in future the necessary btrfs commands will be issued to handle the snapshots instead of the normal cp and rm commands
- Now we need to migrate the existing backups into one subvolume per backup. See the following script to see how this works:
- At the end you should modify your /etc/rsnapshot.conf file so it looks like this one