Automatically Copy CloudKey Backups to NAS

First, mount the remote NAS filesystem directory by editing fstab.

sudo -i
# create the local directory used as the mount point.
mkdir -p /local/autobackup
# install nano
apt-get update
apt-get install nano
# install rsync
apt-get install rsync
# edit fstab
nano /etc/fstab

Add your NAS path into the fstab file

//nas1/Backups/Unifi_CK  /local/autobackup  cifs  username=%USERNAME%,password=%PASSWORD%,iocharset=utf8,sec=ntlm  0  0

Save the file and reload fstab

mount -a

If you get an error about wrong fs type, bad option, bad superblock on //pathToNas, then you need to install helper program.  In my case it’s cifs.  You may need nfs. Pulled from here.

sudo apt install cifs-utils

Now, re-try the mount command.

mount -a

Create a new shell file in /data called backupToNas.sh

cd /data
nano backupToNas.sh

Paste this in

#!/bin/sh
/usr/bin/rsync -rc /data/autobackup/ /local/autobackup --delete

The –delete will remove any backups that aren’t in the CloudKey /data/autobackup/ folder.

Now edit Cron to schedule the script to run every 15 minutes.

crontab -e

#add the folliwing line
*/15 * * * * /data/backupToNas.sh >/dev/null 2>&1