mandag den 24. juni 2013

Nightly Backups over smb

This is just a quickie.

I have a usb drive attached to my boxee box which I share over boxee's inbuilt smb server. This is mounted on my server machine with an /etc/fstab line like:

//192.168.0.100/maxell_hdd /home/csr/boxee cifs user,rw,username=guest,file_mode=0777,dir_mode=0777,guest,auto,uid=1000,gid=1000 0 0

So if I want to backup files from my server machine to the boxee on a nightly basis, how do I do it? rsync is a great tool, but I ran into one problem - every so often the boxee would be offline for some reason or other and the rsync would just copy my files into the mount directory, filling my disk up in no time. So I added a test to see if the boxee was actually mounted. The backup script ended up looking like

#!/bin/bash
#
#
volume="/home/csr/boxee"
if mount | grep "on ${volume} type" > /dev/null
then
  rsync -av --modify-window=1 --ignore-existing  /home/csr/media/Music/ /home/csr/boxee/Music
else
echo 'Nightly sync failed becaue of lack of mount'
fi

I put this in a file /bin/backup.sh and then added it to my nightly cron job.

Update

I've now replaced the boxee box with a NUC Linux box to which I have direct ssh access. This means I can replace the above rsync with something like this:

rsync -av --modify-window=1 --ignore-existing  /home/csr/media/Music/ -e ssh colin@192.168.0.155:Maxell/Music

Ingen kommentarer:

Send en kommentar