Scheduling a Task on a Synology NAS
Running user-defined scripts as scheduled tasks is the best way to backup external data to your Synology NAS. They can easily be created in the Task Scheduler pane of the Control Panel.
However, there are a few important details to be aware of, especially if you're not a versed Linux user:
By default, a newly created scheduled task will be set to run as a
rootuser. This gives it full access to the device which you shouldn't need for most tasks. To avoid inadvertently harming your device, you should choose a different user which still has the permissions required for the script to work. Even
adminis a much safer choice than
Although you can put your full script directly inside the User-defined script field on the Task Settings tab, I suggest you create a bash file instead and invoke that from the User-defined script field. This will make it easier to test the script on your own computer first and also to update it later if necessary. Don't forget to put the shebang directive in the first line to make it executable:
#!/bin/bash wget ftp://user:email@example.com/* -P /volume1/backup/ftp/
When specifying absolute paths on your device, the information visible in the File Station can be misleading. Its address bar doesn't contain the full path. You must prepend it with a folder matching the volume it belongs to (e.g. the absolute path for
/volume1/homes/admin). You can find the volume information in the tooltip when hovering over the top level folder in the
File Stationtree view:
You can avoid putting sensitive information (e.g. login data) in the bash file by using environment variables:
#!/bin/bash wget ftp://$username:$password@$url/* -P $path
You can then set the values for these variables in the User-defined script field on the Task Settings tab before invoking the bash file:
export username=user export password=pwd123 export url=myserver.com export path=/volume1/backup/ftp/ /volume1/homes/admin/backup.sh
To test the task, you don't need modify its schedule. You can just right-click it in the list and invoke it using the Run command.
For troubleshooting, you can enable email notifications on the Task Settings tab to send standard and error output of the script to your email after each run (you need to configure email notifications in the Notification pane of the Control Panel first):
Once your script is working as expected, you can keep the notifications enabled. Just toggle the Send run details only when the script terminates abnormally switch to only receive an email when the task fails.
If for some reason you don't want to use email notifications, you can enable logging to a file for scheduled user-defines scripts in the Settings dialog (click the Settings button at the top of the Task Scheduler pane in the Control Panel to access it):
For each run, the script contents and the output will be saved in a subfolder created at the specified path. No other configuration options are available, i.e. logging will be enabled for all scheduled user-defined scripts, no matter whether they succeed or fail. That's why I prefer email notifications.