How do I backup my Plex data (not media) on Synology NAS with DSM7?

Doesn’t HyperBackup require the Plex Server to be shut down? That’s the hard part - automating the shutdown and the restart.

My understanding is that if it’s not shut down, then the files can be corrupted.

It does and it doesn’t.

If your server is quiet (not scanning / adding media, and not playing anything, and not performing nightly maintenance ) you can get away with it running.

If you want to be perfect.

  1. Scheduled task to stop plex
  2. Set HyperBackup’s schedule to start 2 minutes after it shuts down
  3. Have another scheduled task to start plex.

I’m so sorry to be a pain. I’m new to Synology, but not new to plex. I ran plex on a Linux server for YEARS and ran a corn job that shutdown plex, backup up the metadata folders, and then restarted plex. Why this isn’t an option on Synology, I don’t know.

How do I schedule a task to stop plex? If I could figure that out, I’d be golden. THANK YOU!

SSH into the NAS,
type synopkg (how you control packages in DSM)

chuck@ds418:~$ synopkg
usage: synopkg <command> [...]

command:
  start <package>                                                 Start a package.
  stop <package>                                                  Stop a package.
  restart [--service] <package|searvice>                          Restart one package/one or more services.
  resume <package>                                                Start a package without change its systemd enable status.
                                                                  It will do nothing if package is disable or already active.
  pause <package>                                                 Stop a package without change its systemd enable status.
                                                                  It will do nothing if package is already inactive.
  start-depend <service>                                          Start all packages depend on specific service.
  stop-depend <service>                                           Stop all packages depend on specific service.
  onoffall start|stop [event] [param]                             Start or stop all the packages.
  install <spk>                                 Install a package through local spk.
  install_from_server <package> [volume] [user] [beta]            Install a package from server.
  uninstall <package>...                                          Uninstall one or more package.
  upgradeall [limitonly] [lang] [user]                            Upgrade all upgradable package.
  chkupgradepkg [lang]                                            Find all upgradable packages from server, and decide whether to
                                                                  upgrade accorting to user settings.
  checkupdateall [lang] [user]                                    Find all upgradable packages from server (use cache first), and
                                                                  decide whether to upgrade accorting to user settings.
  status <package>                                                Get status of an installed package.
  is_onoff <package>                                              Check if a package is installed and active.
  version <package>                                               Get version of an installed package.
  query <spk>                                                     Get a package's basic information from the spk.
  list [--name] [--depend-on <package>]                           List installed package.
  checkupdate <package> [lang]                                    Check if a package is updatable.

chuck@ds418:~$ 

I will let you work out HyperBackup (it’s extremely versatile)

chuck@ds418:/volume1/@appstore/HyperBackup$ ls -la
total 48
drwxr-xr-x 12 root HyperBackup 4096 Dec 30 14:10 .
drwxr-xr-x  9 root root        4096 Dec 31 09:59 ..
drwxr-xr-x 22 root root        4096 Dec 20 04:54 addon
drwxr-xr-x  3 root root        4096 Dec 20 04:54 bin
drwxr-xr-x  7 root root        4096 Dec 20 04:54 etc
drwxr-xr-x  4 root root        4096 Dec 20 04:54 feasibilitycheck
drwxr-xr-x  4 root root        4096 Dec 20 04:54 indexdb
drwxr-xr-x  3 root root        4096 Dec 20 04:54 lib
drwxr-xr-x 15 root root        4096 Dec 20 04:54 libexec
drwxr-xr-x  3 root root        4096 Dec 20 04:54 syno
drwxr-xr-x  6 root root        4096 Dec 20 04:54 ui
drwxr-xr-x  2 root root        4096 Dec 30 14:11 webapi
chuck@ds418:/volume1/@appstore/HyperBackup$

Hmmm, ssh is no problem. synopkg doesn’t seem to be working for me.

  1. I tried it with “PlexMediaServer”
  2. I tried it with the FULL name: “PlexMediaServer-1.25.2.5319-7000”
  3. I tried both of those with sudo
  4. And I tried all 4 of those ssh’ed in as my account, “mark” and also ssh’ed in as “admin.”

In every case I got an error. :sob:

mark@Storage:~$ synopkg stop PlexMediaServer
{“action”:“prepare”,“error”:{“code”:0},“stage”:“prepare”,“success”:true}

mark@Storage:~$ sudo synopkg stop PlexMediaServer
{“action”:“prepare”,“error”:{“code”:0},“stage”:“prepare”,“success”:true}

mark@Storage:~$ synopkg stop PlexMediaServer-1.25.2.5319-7000
{“action”:“prepare”,“error”:{“code”:0},“stage”:“prepare”,“success”:true}

mark@Storage:~$ sudo synopkg stop PlexMediaServer-1.25.2.5319-7000
{“action”:“prepare”,“error”:{“code”:0},“stage”:“prepare”,“success”:true}

:rage: :rage: :rage: :rage: :rage: :rage:

Error code 0 == NO ERROR :slight_smile:

But, because you’re not root , it is ignoring you

chuck@ds418:~$ sudo bash
bash-4.4# synopkg status PlexMediaServer
PlexMediaServer package is started
bash-4.4# synopkg stop PlexMediaServer
{"action":"prepare","error":{"code":0},"stage":"prepare","success":true}
bash-4.4# synopkg status PlexMediaServer
PlexMediaServer package is stopped
Status: [3]
bash-4.4#

I execute the script daily via Synology Task Scheduler and the User is “root”. I guess this gets around the need to use sudo

Did you notice you give the package name, without the version number?

The package is “PlexMediaServer”

Your prompt still shows $ (which is not root )

It should be # when you are root.

Alright, so I setup a user defined script to run as root and it appears to have worked like a charm.

date >> /volume1/homes/mark/
synopkg status PlexMediaServer >> /volume1/homes/mark/backup_results.txt
echo “Stopping Plex” >> /volume1/homes/mark/backup_results.txt
synopkg stop PlexMediaServer
date >> /volume1/homes/mark/backup_results.txt
synopkg status PlexMediaServer >> /volume1/homes/mark/backup_results.txt
echo “Backing up folder” >> /volume1/homes/mark/backup_results.txt
rsync -ar --exclude=‘cache’ “/volume1/PlexMediaServer/AppData/Plex Media Server”/ /volume1/Backups/plex/Plex\ Automated\ Backups/
echo “Starting Plex” >> /volume1/homes/mark/backup_results.txt
synopkg start PlexMediaServer
date >> /volume1/homes/mark/backup_results.txt
synopkg status PlexMediaServer >> /volume1/homes/mark/backup_results.txt

I set it to run 5 minutes from when I set it up, and the output file said:

PlexMediaServer package is started
Stopping Plex
Fri Dec 31 18:30:04 EST 2021
PlexMediaServer package is stopped
Status: [3]
Backing up folder
Starting Plex
Fri Dec 31 18:30:13 EST 2021
PlexMediaServer package is started

So looks good to me! Thank you to EVERYONE for your tremendous help. Moving from Linux to DSM is a bit of a learning curve.

“DSM” while it is Linux kernel… is Synology’s special purpose kernel with special purpose tools. it’s “almost” linux haha

I think I got the script to a good place, thanks to all y’all’s help. It ran great last night at 1am.

So I’m posting it here in case anyone wants it (modify the file locations of course).

  • I added more “date” commands so it’s clear when things are happening.
  • I added more comments in the results file to make it more intuitive what’s going on.
  • I made the first write to the output file a single “greater-than” sign so that it creates a new file every time and the file doesn’t grow and grow.
  • I had it create a test file in my plex metadata folder so that I can be sure that rsync really ran.
  • I had it echo the results of the rsync test to the results file

date > /volume1/PlexMediaServer/AppData/Plex\ Media\ Server/rsync-test.txt
date > /volume1/homes/mark/backup_results.txt
synopkg status PlexMediaServer | grep -v Status >> /volume1/homes/mark/backup_results.txt
echo “Stopping Plex” >> /volume1/homes/mark/backup_results.txt
synopkg stop PlexMediaServer
date >> /volume1/homes/mark/backup_results.txt
synopkg status PlexMediaServer | grep -v Status >> /volume1/homes/mark/backup_results.txt
date >> /volume1/homes/mark/backup_results.txt
echo “Backing up folder” >> /volume1/homes/mark/backup_results.txt
rsync -ar --exclude=‘cache’ “/volume1/PlexMediaServer/AppData/Plex Media Server”/ /volume1/Backups/plex/Plex\ Automated\ Backups/
date >> /volume1/homes/mark/backup_results.txt
echo “Starting Plex” >> /volume1/homes/mark/backup_results.txt
synopkg start PlexMediaServer
date >> /volume1/homes/mark/backup_results.txt
synopkg status PlexMediaServer | grep -v Status >> /volume1/homes/mark/backup_results.txt
date >> /volume1/homes/mark/backup_results.txt
echo “Is Plex REALLY running? Let’s do a ps to find out:” >> /volume1/homes/mark/backup_results.txt
ps -ef | grep -i plex | grep -v rsync-test.txt | grep -v grep >> /volume1/homes/mark/backup_results.txt
echo “The time in the rsync test file (to prove rsync ran and worked) is…” >> /volume1/homes/mark/backup_results.txt
cat /volume1/PlexMediaServer/AppData/Plex\ Media\ Server/rsync-test.txt >> /volume1/homes/mark/backup_results.txt

And it worked because the plex server has been running since 1 am.

mark@Storage:~$ ps -ef | grep -i plex
PlexMed+ 8065 1 0 01:00 ? 00:02:44 /volume1/@appstore/PlexMediaServer/Plex Media Server
PlexMed+ 8081 8065 0 01:00 ? 00:00:32 Plex Plug-in [com.plexapp.system] /volume1/@appstore/PlexMediaServer/Resources/Plug-ins-c43dc0277/Framework.bundle/Contents/Resources/Versions/2/Python/bootstrap.py --server-version 1.25.2.5319-c43dc0277 /volume1/@appstore/PlexMediaServer/Resources/Plug-ins-c43dc0277/System.bundle
PlexMed+ 8351 8065 0 01:00 ? 00:00:51 /volume1/@appstore/PlexMediaServer/Plex Tuner Service /volume1/@appstore/PlexMediaServer/Resources/Tuner/Private /volume1/@appstore/PlexMediaServer/Resources/Tuner/Shared 1.25.2.5319-c43dc0277 32600

My thanks, again, to all of you. Happy New Year!!!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.