Backup to USB External drive on Freenas

Backup to USB External Drive on FreeNAS

FreeNAS is an excellent operating system but one thing it lacks is the ability to schedule or otherwise automate backups to an external USB drive. Sure, you can setup ZFS snapshots and then hack it together to ‘zfs send’ these snapshots off to your external drive, however this isn’t always pretty and can sometimes be hard to restore from.

Source: http://www.spiderwebsolutions.com.au/backup-to-usb-external-drive-on-freenas/

Thankfully, we came up with a quick solution that doesn’t involve too much stuffing around.

  1. Mount your external drive within the FreeNAS GUI using the legacy UFS filesystem. Give it an easy name to remember, in this case we will call it ‘offsite’ (While technically the drive doesn’t sit offsite, the point of this is so that it can be taken home each night by a staff member)
  2. Head into view disks and take careful note of the device path. In this case we will be using /dev/da1
  3. Create a backup shell script called backup.sh or similar and chmod execute permissions on it to root.
  4. Stick something similar to this in the file:#!/bin/bash
    mount /dev/da1 /mnt/offsite
    rsync -av --delete /mnt/main /mnt/offsite/data | mail -s "Offsite Backup Log" "youremail@example.com"
    umount /mnt/offsite
  5. Make sure to substitute your device name with the one you found in step 2, and offsite with whatever name you called the volume. This is the case for FreeNAS 9.1.0 and 8.3.0
  6. In this scenario, our mountpoint /mnt/main is what we are backing up. Your location may be a little different.
  7. If using FreeNAS 9.1.1, the device name will be a little different to /dev/da1. You can find out what it is by running the command below. It will usually sit in one of the last lines of the output and be mapped to the mount point with the same name you called the volume.
    df -aTh
  8. Save the .sh file you have created and create a cron job within the FreeNAS GUI to run it at the specified days and times that you want. Redirect stderr.
  9. Remember that this is a current backup and does not include history. If a file is deleted on disk, so is the file on the backup when the backup is next run (–delete command). You can remove this if need be, however you may find the external drive will quickly fill up without further scripting.

That’s it! This has been tested on FreeNAS 8.3.0, 9.1.0 and 9.1.1. This is simply a script to backup when you wish to feel safe in the event of a fire. File versioning and snapshots should still be used where required.

*****************************************************************************************************************************

Simple alternative:  Map the drive on a Windows 7 machine, and use Cobian backup, which enables you to back up mapped drives.  Not as elegant, but it does work.  Cobian can either compress the backup or just copy the files as they are, using VSS.

Leave a comment