Plex Database Backup | Synology Task Scheduler

Server Version#: Version 1.31.1.6782
Player Version#: Version 4.100.1

Hello @ChuckPa,
I am trying to create a script to use with the Synology Task Scheduler to backup my plex database to another location. I am not a linux person but found a script that you posted.

I modified the source and destination but when I execute the script I got a backup file of only 164 bytes.
When I ran the script in the command line it created a backup of 168 mb’s.

Here is the script i am using.

# Plex Backup 
#!/bin/sh
#
# Destination  (set accordingly)
Destination="/volume1/My Home Data - Volume 1/Computers/Operating Systems/Synology/Plex"

# Backup Plex (DSM 7)
cd /volume1/PlexMediaServer/AppData/Plex Media Server/Plug-in Support

# Do it
tar cvzf "$Destination/PlexDatabase-Backup.tar.gz 'Databases'"  ./*

Here is the command line that I used.

tar cvzf PlexDatabaseBackup.tar.gz …/…/…/…/…/volume1/PlexMediaServer/AppData/Plex\ Media\ Server/‘Plug-in Support’/‘Databases’

Can you help making this work properly?

Regards,
Keith

Moderator Edited: Added </> code formatting

One of us forgot quotes around the “cd” statement (probably me). Quotes are needed when spaces are involved in names.

Given things are more stable now with DSM 7 and Plex, let me rewrite it for you

  • This Scheduled Task must run as user ‘root’ . (to start / stop Plex)
#!/bin/sh

# Set destination
Dest="/volume1/My Shared Folder"


# Stop Plex
synopkg stop PlexMediaServer
Result=$?

if [ $Result -ne 0 ]; then
  echo ERROR $Result when stopping PlexMediaServer.
  echo Backup aborted.
  exit 1
fi

# Dest exists ?
[ ! -w "$Dest" ] && echo ERROR: Cannot write to '$Dest' && exit 2

# Get into the databases directory  (this is now volume independent)
cd "/var/packages/PlexMediaServer/shares/PlexMediaServer/AppData/Plex Media Server/Plug-in Support/Databases"

# Create filename using Date/Time  (yyyy-mm-dd_hh-mm)
# Backup
tar cvzf "$Dest/Plex-Database-Backup_$(date +%Y-%m-%d_%H-%M).tar.gz" .
Result=$?

# Check result
[ $Result -ne 0 ] && echo ERROR Got exit code $Result from tar.  Please check && exit 

# Restart Plex
synopkg start PlexMediaServer

How the names work out.

chuck@ds418:~$ Dest=/Path/Somewhere
chuck@ds418:~$ echo $Dest/Plex-Database-Backup_$(date +%Y-%m-%d_%H-%M).tar.gz
/Path/Somewhere/Plex-Database-Backup_2023-03-12_20-21.tar.gz
chuck@ds418:~$ 

Tweak as appropriate

Thanks Chuck, I got it to work.
It is really comforting having a backup of my database.
Perhaps you would want to post this to the top of the forum for others users?

I’ll post in in Syno FAQ

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