The End

Home NAS, Part 3: Local and Cloud Backups
July 24, 2016

Local Backups

Given a primary zpool of /tank and a backup zpool of /garage, the following code snippet will provide a very fast and robust backup strategy that sends snapshots from one pool to another. Compared to other archiving tools such as rsync, this approach is much more efficient because ZFS knows exactly which blocks have changed from one snapshot to another and does not need to analyze the content at the file level. This will pay off when backing up large files such as encrypted file containers. You will not have to read the entirety of an 800G encrypted file container just to identify the 30M that have changed, for instance.

Create a snapshot of your dataset and perform the initial backup:

    sudo zfs snapshot -r tank@2016-06-17
    sudo zfs send -R tank@2016-06-17 | sudo zfs recv garage/tank
  

Make changes to your data, take another snapshot, then send the incremental changes to the backup destination:

    sudo zfs snapshot -r tank@2016-06-18
    sudo zfs send -R -i tank@2016-06-17 tank@2016-06-18 | sudo zfs recv garage/tank
    sudo zpool export garage
  

Cloud Backups

Cloud storage aims to simplify storage concerns for the end user, but it introduces its own collection of issues as well. Users should no longer have to worry about all of the inconveniences that come along with long-term, durable storage such backups, version control, integrity (bitrot), hardware and drive replacement, expansion, electricity, noise, and up-front purchase costs. In exchange for these benefits, however, users who care about their privacy, security, and time need to be aware of encryption (local vs. remote), synchronization and restoration durations, and getting locked into proprietary formats that cannot be easily migrated to other systems or software if desired.

Some backup solutions, such as Crashplan, will attempt to provide encryption along with the provided storage. This may be acceptable to some users, but separating concerns by having one application that provides encryption and another that provides storage synchronization seems to be better security.

Encryption Synchronization Automation

Cloud synchronization can be easily automated even when using command line tools. I synchronize with Amazon Cloud Drive on a daily basis using rclone. The following script will only allow one backup session at a time to occur.

        #!/bin/bash
        . /home/gary/.profile
        (
            flock -x -w 10 200 || exit 1
            string="$(df)" 
            if [[ $string == *"encfs/media"* ]]
            then
                echo "media is mounted";
                rclone sync --bwlimit $1k --exclude o9Lb4SkpD-4BREOdivP7CdNV/** --transfers 1 /home/gary/encfs/media ACD:media;
            fi
        ) 200>/var/lock/.acdBackup.exclusivelock
      

Now that we have a script that performs the sync, we can schedule it as needed using crontab.

        crontab -e
        40 0 * * * /home/gary/acdBackup.sh 1200 >> /home/gary/acdBackup.history 2>&1
      


© 2016 |