I know I’m a bit late to this post, but this is something I’ve started working on (again), I would have a completed script for you but I got lazy and didn’t finnish it, now that I am upgrading my server I’ve kicked myself into gear to get this done.
For me, the best approach is powershell, but you can use cmd or even vbscript, what you need to decide is how you want to deal with the backup.
You can back it up to a drive, secondary machine or store it online in a cloud service, you also have two options, either copy plex to your chosen location or compress it first then send it to your chosen location.
I’m going to give you some examples, as I said I’m not finnished creating my backup script and I’ll not just be backing up plex but sonarr, radarr and other applications, so while what I’m about to provide will work, how you implement it is entirely up to you, and remember, I’m using powershell.
First of all we have some variables, $Backup, $Plex_Dir, $Plex_Reg
$Backup = "Your_Backup_directory"
$Plex_Dir = "$env:LOCALAPPDATA\Plex Media Server"
$Plex_Reg = "HKCU\Software\Plex, Inc.\Plex Media Server"
Your backup directory can be anything, but if you’re going to do this over a network then ofcourse make sure you’re using a valid network path, in my case I’ll be transfering the backup to a google drive folder once its been compressed and my path will look something like this “c:\google_dirve”
So first things first, shutting down plex, if you run it as a service there is a cleaner way to shut it down, if not then we have to do it a dirtier way, the following will terminate plex.
taskkill /f /im "Plex Media Server.exe" /t
If you have it running as a service, then you’d run this command
net stop <service name>
Next, for me, I prefer to send my registry file for plex to the $Plex_Dir, that way, when I back it up, the registry is safe and sound in the plex folder.
The following code will export the $Plex_Reg to the $Plex_Dir
reg export $Plex_Reg "$Plex_Dir\Plex.reg"
Next you need to decide how you want to handle the plex_dir and whether or not you wish to exclude certain folders.
If you’re going to compress it you need to decide what you’re going to compress it with, I chose 7za which is a standalone version of 7zip, this means I don’t need to install 7zip to do what I want, I also chose to split the backup into 1 Gigabyte files, this makes it easier to upload/download to/from my google drive.
My command for this is the following.
$7zexe = 'C:\Users\username\Desktop\7z\64\7za.exe'
$7zcmd = @(
'a'
'-t7z'
"$Backup\plex.7z"
$Plex_Dir
'-mx0'
'-xr!Plex Media Server\Diagnostics'
'-xr!Plex Media Server\Scanners'
'-xr!Plex Media Server\Crash Reports'
'-xr!Plex Media Server\Updates'
'-xr!Plex Media Server\Logs'
'-v1g'
)
& $7zexe $7zcmd
-xr! is basically telling 7zip to exclude those folders, because I don’t need them in my backup and depending on the situation, I may not want to backup my cache folder either, if thats the case then I simply add this to the script above -xr!Plex Media Server\Cache, if you don’t want to split the file then remove -v1g from the code above.
If you’re looking to simply copy the plex folder you can use robocopy which is available in most windows OS, just open your cmd and type robocopy, if you don’t have it, then you will have to use something like xcopy.
Robocopy.exe "$Plex_Dir" "$Backup\Plex Media Server" /MIR /W:5 /R:2 /MT:24 /XD 'Logs' 'Crash Reports' 'Diagnostics' 'Scanners' 'Updates' 'Cache'
In the code above we’re excluding the same folders, except this time I’ve included the cache folder.
To start your server, if its a service you change the net stop to net start, or in powershell you run Start-Process "C:\Program Files (x86)\Plex\Plex Media Server\Plex Media Server.exe"
Something else, I would add to this, would be to delete the .reg file we exported to the plex directory, Remove-Item "$Plex_Dir\Plex.reg"
That’s pretty much it, powershell restricts custom scripts, so you will need to temporarly run –ExecutionPolicy Bypass when executing your script or you can remove the restriction so you don’t need to run that, the code would look something like this
powershell –ExecutionPolicy Bypass "& 'd:\script\backupplex.ps1'"
If you prefer to simply call the script without the bypass, then you’ll need to run Set-ExecutionPolicy RemoteSigned, use google to learn more before you decide to change your execution policy.
With that all said, depending on the method you chose, your script will look something like this.
$Backup = "Your_Backup_directory"
$Plex_Dir = "$env:LOCALAPPDATA\Plex Media Server"
$Plex_Reg = "HKCU\Software\Plex, Inc.\Plex Media Server"
$7zexe = 'C:\Users\username\Desktop\7z\64\7za.exe'
taskkill /f /im "Plex Media Server.exe" /t
reg export $Plex_Reg "$Plex_Dir\Plex.reg"
$7zcmd = @(
'a'
'-t7z'
"$Backup\plex.7z"
$Plex_Dir
'-mx0'
'-xr!Plex Media Server\Diagnostics'
'-xr!Plex Media Server\Scanners'
'-xr!Plex Media Server\Crash Reports'
'-xr!Plex Media Server\Updates'
'-xr!Plex Media Server\Logs'
'-v1g'
)
& $7zexe $7zcmd
Remove-Item "$Plex_Dir\Plex.reg"
Start-Process "C:\Program Files (x86)\Plex\Plex Media Server\Plex Media Server.exe"
OR
$Backup = "Your_Backup_directory"
$Plex_Dir = "$env:LOCALAPPDATA\Plex Media Server"
$Plex_Reg = "HKCU\Software\Plex, Inc.\Plex Media Server"
$7zexe = 'C:\Users\username\Desktop\7z\64\7za.exe'
net stop "Plex Media Server" <<or whatever your service name is
reg export $Plex_Reg "$Plex_Dir\Plex.reg"
Robocopy.exe "$Plex_Dir" "$Backup\Plex Media Server" /MIR /W:5 /R:2 /MT:24 /XD 'Logs' 'Crash Reports' 'Diagnostics' 'Scanners' 'Updates' 'Cache'
Remove-Item "$Plex_Dir\Plex.reg"
net start "Plex Media Server" <<or whatever your service name is
You can also beef this up a bit by including some safety precautions, such as checking to see if the backup was succesful, testing the existence of the directory/registry paths etc…
Powershell is very useful and I would recommend you learn even the basics, I have a powershell script that automates sonarr, radarr and plex, it also extracts any files that need extracted, but its something I’m not willing to share just yet as I feel it can be improved upon 
You can download 7za from here , you’re looking for 7-Zip Extra: standalone console version, 7z DLL, Plugin for Far Manager
Once I’ve finnish my script and I’m happy with the results I will share it with the community, I think others have already done this, if you haven’t already consider searching the forums for other plex members scripts, try searching “powershell plex scripts” or something like that, anyway, I hope this helps, good luck.