Backup the Synology Task Scheduler

If you are like me and enjoy poking around under the hood of your Synology, you are probably using the DSM Task Scheduler to accomplish many recurring tasks. One concern I had recently is how to backup the configuration of the Task Scheduler. Unliking piping crontab -l to a file, Synology does not appear to provide any documentation on command line operations against the DSM Task Scheduler. I knew there were various syno* commands available, but was not sure if any existed for the Task Scheduler.

I am going to deviate from the topic of this post momentarily, but for what I feel is a good reason. I enjoy exploring what I can do via SSH/CLI (and therefore scripting), so locating the available commands is just the first step. My Synology has a rather large data set and using the find command can become problematic. I decided to do some searching on how to exclude directories like (/volume1) from find's search process. First, I came across answers that simply excluded the results, but not the effort of searching my entire data volume. Then, I found -prune. If I am being honest, I am not quite sure exactly how this command works to skip searching the data volumes, but I know it works. The search completes very quickly as opposed to hours. Without further delay, here is the command I ran to discover executable syno* files:
find / -path '/volume*' -prune -false -o -type f -perm /111 -name syno* | sort | less
I ended up discovering the following seemingly-related commands (looking for anything with "sch" or "task"):
/usr/libexec/user_delete/synoscheduler_user_delete.sh
/usr/share/init/synoscheduler-vmtouch.conf
/usr/share/init/synoscheduler.conf
/usr/syno/bin/syno_disk_test_scheduler_set
/usr/syno/bin/syno_hungtask_config
/usr/syno/bin/syno_poweroff_task
/usr/syno/bin/synoschedtask
/usr/syno/bin/synoschedtool
/usr/syno/bin/synosnapschedtask.sh
/usr/syno/bin/user.data.collector/synouserdata_esynoscheduler
/usr/syno/bin/user.data.collector/synouserdata_synoscheduler
The two that stood out from this list were synoschedtask and synoschedtool.  Running them with --help showed:
# /usr/syno/bin/synoschedtask --help
Copyright (c) 2003-2020 Synology Inc. All rights reserved.

Usage: synoschedtask (Version 25426)
        --get [<id=x> <state=disabled|enabled> <owner=x> <type=once|yearly|monthly|weekly|daily>]
        --del <id=x>
        --run <id=x> [check_time=0|1(default)] [check_status=0|1(default)]
        --reset-status
        --sync
        --help

# /usr/syno/bin/synoschedtool --help
Copyright (c) 2003-2020 Synology Inc. All rights reserved.

Usage: synoschedtool (Version 25426)
        --beep <duration (seconds), 0 means stop)
        --start-service 
        --stop-service 
        --help
The output of /usr/syno/bin/synoschedtask --get is exactly what I was seeking:
               ID: [#]
             Name: [Task Name]
            State: [enabled]
            Owner: [root]
             Type: [daily]
       Start date: [0/0/0]
         Run time: [0]:[0]
Repeat every [10] min (s) until [23]:[50]
          Command: [/path/to/script.sh]
    Last Run Time: Tue Apr 14 12:40:03 2020
           Status: [Success]
I have this now setup as a scheduled task to output this to a file (which is backed up).

Comments

Popular posts from this blog

Palo Alto Breaks FQDN NAT's with PAN-OS 9.x

Welcome to the Matrix