-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBackup-Plex.ps1
46 lines (34 loc) · 1.29 KB
/
Backup-Plex.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Backup-Plex
# Simon Tims
# Settings
$mirror = "D:\Backup\Plex"
$destination = "\\bubblenas1\general\backups\Plex"
$tempLocation = "C:\temp"
# Do not change anything below this line
##################################################
# Load ZipFile .NET Framework
Add-Type -assembly "system.io.compression.filesystem"
# Build paths
$regKey = "HKEY_CURRENT_USER\Software\Plex, Inc.\Plex Media Server"
$source = Join-Path -Path $env:LOCALAPPDATA -ChildPath "Plex Media Server"
$cacheFolder = Join-Path -Path $source -ChildPath "cache"
$metadataFolder = Join-Path -Path $source -ChildPath "Metadata"
$regKeyFile = Join-Path -Path $mirror -ChildPath "PlexRegistryKey.reg"
$zipFile = Join-Path -Path $tempLocation -ChildPath "Plex.zip"
# Mirror Plex data folder
robocopy $source $mirror /MIR /NFL /NDL /R:0 /W:0 /XD $cacheFolder /XD $metadataFolder
# Export Plex Registry key
Reg export $regKey $regKeyFile
# Zip file should have been removed already; double check and remove if present
if (Test-Path $zipFile) {Remove-Item $zipFile}
# Zip folder to zipfile (cannot be the source folder we are zipping)
[io.compression.zipfile]::CreateFromDirectory($mirror, $zipFile)
# Move zipfile to destination
try
{
Move-Item $zipFile $destination -Force
}
catch
{
Write-Host "Unable to move $zipfile to $destination"
}