Linux: incremental backup using rsync on btrfs with snapshots

From Luky-Wiki
Revision as of 15:49, 21 February 2014 by Lukas Dzunko (talk | contribs) (Before first backup)

Jump to: navigation, search

My production data are backed up by bacula. This is good for data "online" all the time, but it is not so convent for my notebook and media PC. Till now I was using only simple rsync script to "copy" everything important to USB drive or iSCSI LUN. This solution was working fine but hat one catch. There is no way how to retrieve older version of files.

I would like to have possibility to retrieve also older versions of files so i combined my rsync backup with btrfs and snapshot feature. Here is result:

Before first backup

I am using iSCSI lun as target for backup. Skip iSCSI part if you are using USB drive.

iSCSI configuration

It is important to password protect Target. Otherwise any device on local network can overwrite it. Also highly recommend to use Header and Data Digest. There is possibility of data corruption without it.

Configuration of iSCSI initiator is stored in /etc/iscsi/iscsid.conf. Following lines are mandatory:

node.session.auth.authmethod = CHAP
node.session.auth.username = 
node.session.auth.password = 

node.conn[0].iscsi.HeaderDigest = CRC32C
node.conn[0].iscsi.DataDigest = CRC32C

All others can be left in "default" configuration.

iSCSI discovery and login

It is necessary to discover iSCSI target and log to it before system can access drive. It can be performed by following commands:

# iscsiadm -m discovery -t st -p prue-nas
10.xx.xx.5:3260,0 iqn.2000-01.com.synology:prue-nas.phoebe
10.xx.xx.5:3260,0 iqn.2000-01.com.synology:prue-nas.lukas

# iscsiadm -m node -T iqn.2000-01.com.synology:prue-nas.phoebe --login
Logging in to [iface: default, target: iqn.2000-01.com.synology:prue-nas.phoebe, portal: 10.xx.xx.5,3260]
Login to [iface: default, target: iqn.2000-01.com.synology:prue-nas.phoebe, portal: 10.xx.xx.5,3260] successful.

There should be new disk once kernel detect it:

# lsscsi | grep SYN
[6:0:0:0]    disk    SYNOLOGY iSCSI Storage    3.1   /dev/sdb 

filesystem

I prefer disk labels as device file may change over time:

# mkfs.btrfs -L phoebe-backup /dev/sdb

Turning ON incompat feature 'extref': increased hardlink limit per file to 65536
fs created label phoebe-backup on /dev/sdb
	nodesize 16384 leafsize 16384 sectorsize 4096 size 50.00GiB
Btrfs v3.12

fstab

  1. data backup

LABEL=phoebe-backup /mnt/backup btrfs noauto 0 0

mkdir -p /mnt/backup mount /mnt/backup


subvolume

  1. btrfs sub create /mnt/backup/phoebe

Create subvolume '/mnt/backup/phoebe'