Rsync And Encrypted Containers

My 'little' off-site Raspberry Pi backup/remote storage project will probably use a combination of Bittorrent Sync and rsync. The latter will be used to backup personal information, but I want that data to be absolutely secure. So I want to use encryption. Preferably by using container that I can mount (e.g. Truecrypt or the Apple OSX encrypted disk images).

The problem with containers is that many backup solutions tend to backup / transfer the entire container when a change occurred. Thankfully, rsync only copies the changes.

Consider the following; I created a 100MB encrypted container (Apple disk image). After the creation, I copied the container with rsync to the Raspberry Pi. Copying the initial 100MB container completed in 38 seconds.

$ rsync -avzhu --progress --stats ~/Dropbox/ pi@10.8.0.10:/media/external/Dropbox/
building file list ... 
PriveData.dmg
     102.54M 100%    2.51MB/s    0:00:38 (xfer#2, to-check=12788/12798)
Number of files: 12798
Number of files transferred: 1
Total file size: 5.05G bytes
Total transferred file size: 102.54M bytes
Literal data: 102.57M bytes
Matched data: 49.78K bytes
File list size: 334114
File list generation time: 0.118 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 102.54M
Total bytes received: 774

sent 102.54M bytes  received 774 bytes  2.26M bytes/sec
total size is 5.05G  speedup is 49.16

After the copy, I added several files in the disk image and did another rsync.

$ rsync -avzhu --progress --stats ~/Dropbox/ pi@10.8.0.10:/media/external/Dropbox/
building file list ... 
12798 files to consider
PriveData.dmg
     102.54M 100%   50.30MB/s    0:00:01 (xfer#1, to-check=12788/12798)

Number of files: 12798
Number of files transferred: 1
Total file size: 5.05G bytes
Total transferred file size: 102.54M bytes
Literal data: 303.60K bytes
Matched data: 102.24M bytes
File list size: 334114
File list generation time: 0.095 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 637.94K
Total bytes received: 70.97K

sent 637.94K bytes  received 70.97K bytes  45.74K bytes/sec
total size is 5.05G  speedup is 7129.02

This time, the rsync copy took about 1 second (same concept works with TrueCrypt containers). This means that you can use these encrypted containers with rsync, without uploading the entire container after a change of its contents.

Posted on June 20, 2015 and filed under Raspberry Pi, Security, Software, Tips'n Tricks.