Backup Synology NAS to Rsync Server (part 2)

13 07 2013

In my previous post I described how to backup synology NAS to an external rsync server in a fast way. The rsync server is supposed to be always powerd on. In a home environment this could be not wanted.
Here I describe how to setup a kind of automated backup, with rsync server turning on and off thorugh Wake on lan (WOL) and crontab.

Objective: NAS (always powerd on) power-on rsync server (Ubuntu 11.10) through WOL, then starts and finishes backup. In the end, rsync server shutdowns. Rsync server waits for the next scheduled backup.

Rsync server need to be WOL enabled.
In my case the Gigabyte Z68MA-etc-etc.. motherboard does. You can check your motherboard manual or BIOS setting. In my BIOS setting I find “Power Management Setup”, than “PME Event Wake up” must be enabled. I also noticed that “ErP Support” must be disabled in order WOL to work. Also “AC back function” is important: I set it to “Memory”.

Whatever your personal settings are, you must be sure WOL is supported by your server. Once you do, you must find a script that is capable of remotely wakeup your server. I found this one: http://code.activestate.com/recipes/358449/. It is a python script, say, wol.py. Notice that you have to modify the last lines of it and insert the MAC address of YOUR server.

if __name__ == '__main__':
# Use macaddresses with any seperators.
wake_on_lan('0F:0F:DF:0F:BF:EF')
wake_on_lan('0F-0F-DF-0F-BF-EF')
# or without any seperators.
wake_on_lan('0F0FDF0FBFEF')

In order to run wol.py from your NAS, it must support python. My Synology (DSM version 4) has a “Python” packet in the Packet Center. If your NAS has it too, install it. Now save wol.py in your favorite path in the NAS (say, /usr/local/bin).

Ok, now you have a python-enabled NAS with a wake-up-capable script and a wake-on-lan-enabled server. You only have to schedule crontab on the NAS to run the processes.

Modify /etc/crontab on your NAS adding your preferred rules. Exampli gratia, add the following rules:

...
...
#Backup 1
57      11      1       *       *       root    /usr/local/bin/python /usr/local/bin/wol.py
00      12      1       *       *       root    /usr/syno/bin/synonetbkp -a "Backup 1"
#Backup 2
57      11      2       *       *       root    /usr/local/bin/python /usr/local/bin/wol.py
00      12      2       *       *       root    /usr/syno/bin/synonetbkp -a "Backup 2"

Here you are saying: every first day of every month, at 11.57 AM run wol.py, thus wake up the rsync server. Than, at 12.00 AM, run “Backup 1”. Slightly the same thing for “Backup 2”.

Notice that “Backup 1” and “Backup 2” must exist in the NAS. You must create them with the web based GUI, as explained in my previous post.
Save your modified /etc/crontab.

Your server is now waking up as scheduled. How to shut it down? Well, I ended up with a rough solution. I calculate the time my backups are going to take. Let say maximum 5 hours each. Than I schedule (through crontab) the server to shutdown after five hours from the beginning of the backup.
My server side /etc/crontab is then:

...
...
#shutdown after backups
00      17      1,2       *       *       root    /sbin/shutdown -h now

Save and reboot or adjust for your requirements.

Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s




%d bloggers like this: