Synology has created wonderful devices and a marvelous operating system on these devices. The applications they offer on these devices makes that we love our Synology so much. For almost any task we can think of is a package available and if it isn’t available from Synologys repository there are many 3th party repositories to fill the gap.
One of the applications delivered by Synology is the Backup and replication tool. It fulfills the task of backing up our precious data stored on the volume or volumes of our DiskStation. They also added features to backup the settings of some applications they offer in their repository of packages. The Backup and replication tool only can access the volumes of the DiskStation, not the files stored in the root of the filesystem and its descendants other than the volumes. Unfortunately we can’t expect that they also backup settings of applications they didn’t even know that they exist. On the other hand we use these applications and it would be nice to have a mechanism to backup at least the configurations of these applications for obvious reasons. With some self support a shell script and the scheduled task function of the DiskStation, it is possible to create a reliable mechanism to backup the files you can’t access directly with the Backup and replication tool.
The idea is simple: create a script that puts all the files and folders mentioned in a separate file in a tar archive. Make sure the archive is stored in an area that can be backed up with the Backup and replication tool. The configuration files may contain sensitive information (i.e. passwords). Make sure the area is only accessible to the users (administrators) that are allowed to see the content of these files.
If you are using a Windows machine the best thing to do is using WinSCP. WinSCP helps you to access the filesystem of your DiskStation and makes sure the text files you create have the right encoding. This ensures that the scripts you write actually do work. See Getting access to Synology’s filesystem elsewhere on this site.
The script is straight forward:
# Creates backup folder if it doesn't exist.
if [ ! -d "$BU_FOLDER" ]; then
# Create backup of the files and folders in $LIST
tar czf "$BU_FILE" --dereference --files-from "$LIST"
the script is called confbackup.sh but can have any name you like as long as it has a .sh extension. Also make sure it has the right permissions: the execute bit should be set and the right owner and group should have access to the script. A ‘750’ would do the job when the owner is ‘root’ and the group is ‘root’ too.
There are two ‘variables’ that should have some attention; LIST and BU_FOLDER. The variable LIST contains the full path and file name to the file containing all the files and folders to backup in the archive. Make sure the file exists on the location you enter here. The BU_FOLDER is the folder where the archive is being stored. It will be created when it doesn’t exist. This location should be in the area you can access with the Backup and replication tool to be able to backup the archive. Don’t put a ‘/’ at the end. the variable BU_FILE adds it when it ‘builds’ the file name of the archive file.
The tobackup.lst file will look like this:
Each line contains either a folder or a file. Symbolic links will be replaced when the archive is build. When a folder is selected all the sub-folders will be included. If you want to alter the set of files to be backed up in the archive, you just alter the tobackup.lst accordingly.
The only thing left to do is to schedule a task to execute the script periodically. This can be done with Synology’s Task Scheduler that can be found in the Control panel of your DiskStation. Just create a user-defined script task. Enter a logical task name in the Task field. Use root as user context to run the script in. The Run command is the user-defined script: /volume1
/ConfBackup/confbackup.sh. (Make sure the path and the file name are the same as you use.) In the schedule tab you can define a schedule to run the script. If you don’t change much once a week will be sufficient. Otherwise you can set any schedule that suits your needs.