unRAID + ownCloud, Cron, and Rsync Backups

Intro

A while back I set up an ownCloud server running on a unRAID 5.x box. Initially a experiment, I’ve now fully switched to ownCloud on all of my devices and fully dropped Dropbox (pun intended). If Condoleezza Rice being on the board of Dropbox doesn’t make you want to drop it like a bad habbit, I don’t know what will.

With all of this data now on ownCloud, I need solid backups…

A sloppy solution

My scheme is the following-ish:

  1. ownCloud data stored on unRAID so it get’s the benefit of parity.
  2. Data is synced every day at 4AM to an area on a local Windows box.
  3. The backup area on said Windows box is backed up to an external USB drive
  4. The backup area on said Windows box is also fully synced to Backblaze

Item’s #3 and #4 were already the case for other reasons. To achieve #2, I threw together some scripts…

Scripts

First, the actual rsync script @ /boot/config/custom/ownCloudBackup.sh:

#!/bin/sh

#    Ensure we have a mount directory
mkdir -p /mnt/Nu64_ownCloud_BACKUP

#    Mount if required
if mount | grep /mnt/Nu64_ownCloud_BACKUP > /dev/null; then  
    echo Already mounted
else  
    echo Mounting
    mount -t cifs //Nu64/ownCloud_BACKUP /mnt/Nu64_ownCloud_BACKUP/ -o user=USERNAME,password=PASSWORD
fi

#    Rsync on over
rsync --progress -Aax /mnt/disk3/owncloud_data/ /mnt/Nu64_ownCloud_BACKUP/owncloud_data-BACKUP  
rsync --progress -Aax /mnt/disk1/www/owncloud/ /mnt/Nu64_ownCloud_BACKUP/www_owncloud-BACKUP  

I then created a file with a crontab entry @ /boot/config/custom/ownCloudBackupCron:

#    Backup ownCloud
* 4 * * * /boot/config/custom/ownCloudBackup.sh

Lasty, unRAID likes to replace your crontab at every boot. To remedy this, cat the above script into /var/spool/cron/crontabs/root at every boot by adding a line to /boot/config/go:

cat /boot/config/custom/ownCloudBackupCron >> /var/spool/cron/crontabs/root  

That’s about it! At some time I may make the whole thing a bit fancier, but this should do for now.