Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore didn't work too well for me #87

Closed
mkitchingh opened this issue Apr 3, 2024 · 16 comments
Closed

Restore didn't work too well for me #87

mkitchingh opened this issue Apr 3, 2024 · 16 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@mkitchingh
Copy link

mkitchingh commented Apr 3, 2024

I have the latest Plex 64 Bit on Windows with Plex Pass. PlexBackup.ps1 was PlexBackup v1.5.3. Backup command is
powershell -file c:\script\PlexBackup.ps1 -Type 7zip -BackupRootDir D:\Files\PlexBackups -Log -Errorlog
Backups look like they work well, but I have have never tested them more than looking at the contents. Server failed today, and I started migrating to a new server. I installed the latest Plex 64 bit, and downloaded the latest PlexBackup.ps1. I ran the restore command
PlexBackup.ps1 -Mode Restore -BackupDirPath "d:\Files\PlexBackup\<latest bakup dir"
It seemed to work properly, except it was unable to start plex. It had an error that included the path to the plex media server.exe file, which was correct. I launched plex, and none of my libraries were there. The old server was still there with libraries with warnings on them. All the media files were on the new server in the exact same location. I deleted the old server from authorized devices. I tried everything I could think of, but nothing seemed to work. I couldn't get all my old libraries and settings added to the new server. After a few hours, I changed course and repaired the old server. Moving the hard drives to a similar device got me up and running again. Obviously my backup plan isn't working. I backup my media separately, but my hope was after putting the media in the correct place, I could just restore everything with this script. Any ideas?

@alekdavis alekdavis self-assigned this Apr 3, 2024
@alekdavis alekdavis added the help wanted Extra attention is needed label Apr 3, 2024
@alekdavis
Copy link
Owner

Do you have log files from your last backup and restore? Can you share? How did you move the backup files to the new server? What was the error? Did you perform restore using the same account as on the old server? It's really hard to guess what went wrong based on your description, but I have done a few restores myself and people report not having any issues, so can't really say what happened in your case.

@mkitchingh
Copy link
Author

mkitchingh commented Apr 3, 2024

Backup.log
I have backup logs. It is attached. I don't have a restore log. It output to the powershell window, and it was very basic. It had successes and then indicated it couldn't start plex. No details on why. I can try again on a new machine if needed. The backup files and data were on a secondary hard drive. I put the drive in the new server. It had the same letter, paths, etc. The account was named mkitchin on both machines. I see in the logs, the actual folder path included Matthew Kitchin. I don't have the new machine I was trying to restore to anymore, because I had to scavenge it to fix the old machine. Is it the folder paths and registry hive paths that have to match exactly? I can test some more. I've also updated my backup script file to the latest now.

@alekdavis
Copy link
Owner

The backup log looks fine, but the restore log would be more helpful. Now with your new machine gone, and no log, I'm not sure what we can do. Do you have at least the full error message you got on the failed attempt to restart PMS?

@mkitchingh
Copy link
Author

I don't have it. It was very short and generic. I can try to reproduce it. What is it that has to match between the old an new machines? The login name, full name, user directory path, etc.?

@alekdavis
Copy link
Owner

The restore process is not terribly complex. I do not think anything really needs to match. There are two things being restored: (1) PMS app data files and (2) registry key(s). The important step is that as for the backup step, during restore you need to be logged in as the same account, under which PMS runs. By default, it assume that the files (1) will go the the default PMS APPDATA folder. You can change it, but it must match what you have in the PMS config. So, once the files get copied, the next step is registry restoration. The registry file should point to the currently logged in user, so as long as you run it under the righ account, it should be imported into the correct hive, even regardless of user ID. The PMS process should not be running. A normal sequence would be: install PMS, launch it to make sur it runs, then run restore (which will stop PMS and restart it at the end). So if PMS cannot start after restore, I would check logs (under the PMS APPDATA folder), Windows event log to see if there are descriptions of errors.

@mkitchingh
Copy link
Author

Thanks. I will test that now. PMS started fine for me manually, just not in the restore script. I'm not sure why.

@mkitchingh
Copy link
Author

mkitchingh commented Apr 5, 2024

I tried it on a test machine for the restore, and I get the same error on starting PMS. PMS is a fresh install running as my user account.

PS C:\temp> .\PlexBackup.ps1 -Mode Restore -BackupDirPath "\\10.0.10.10\files$\PlexBackups\20240403103015"

NuGet provider is required to continue
PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The NuGet
 provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or
'C:\Users\Matth\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider by running
 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install and
import the NuGet provider now?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y
PlexBackup v2.1.7 (c) Alek Davis
Script started at:
  04/05/2024 12:48:42
Operation mode:
  RESTORE
Backup type:
  DEFAULT
Plex version:
  1.40.1.8227
Backup version:
  1.40.1.8227
Stopping Plex services:
  Plex Update Service
Stopping Plex Media Server process:
  Plex Media Server.exe
Restoring Plex app data folders.
Importing registry key file:
  \\10.0.10.10\files$\PlexBackups\20240403103015\3\55284a6f7b667f3761eb0f017c2d891a.reg
Restore operation completed.
Starting Plex services:
  Plex Update Service
Starting Plex Media Server:
  C:\Program Files\Plex\Plex Media Server\Plex Media Server.exe
RUNAS ERROR: Unable to run - C:\Program Files\Plex\Plex Media Server\Plex Media Server.exe
87: The parameter is incorrect.
 Plex app data size:
  85 files and folders
  0 GB of data
Script ended at:
  04/05/2024 12:49:22
Script ran for (hr:min:sec.msec):
  00:00:39.949
Script execution result:
  SUCCESS
Done.
PS C:\temp>

The file is there, and it will start if I run the command manually.

C:\>dir "Program Files\Plex\Plex Media Server\Plex Media Server.exe"
 Volume in drive C has no label.
 Volume Serial Number is 6C47-87D9

 Directory of C:\Program Files\Plex\Plex Media Server

03/14/2024  02:19 PM        28,645,664 Plex Media Server.exe
               1 File(s)     28,645,664 bytes
               0 Dir(s)   8,346,804,224 bytes free

@alekdavis
Copy link
Owner

alekdavis commented Apr 7, 2024

Ah, the infamous error 87. If you do a search in the issues, you will find a number of complaints about getting it when trying to restart PMS (mostly after backup, but for restore, the idea should be the same). It is apparently due to a bug in the OS caused by some hot fix. I added a parameter -machine to address it, so hopefully if you run it with this parameter, it should fix the problem (see https://github.com/alekdavis/PlexBackup/releases/tag/v2.1.7). But if there store works without any other errors and you can start PMS manually (not via the script), the point is that your restore was successful. You may get the same error when you run the backups, so again =, try adding this parameter and see if it fixes the issue.

@mkitchingh
Copy link
Author

I shutdown the test machine after the restore. I just tried to boot it back up, and it got the most generic error you can imagine. I am able to reproduce it by trying to start plex. All I did on this test machine is install Plex, and stop. I didn't go through full setup wizard after install. See attached pic for the error. I'm just trying to validate that I can use this program to recover Plex after a failure.
image

@alekdavis
Copy link
Owner

Without being able to poke around your system, it's hard to say what went wrong. I'm not sure what you mean by "All I did on this test machine is install Plex, and stop. I didn't go through full setup wizard after install." Did you not complete the Plex installation? As I said before, the sequence is to (1) Install Plex, (2) launch PMS, (3) run restore script. The restore process is simple: it stops PMS, copies app data files, imports registry, and starts PMS. Now, if you change something (like use 64-bit Plex on a new system, when you used 32-bit Plex on the old system, or change paths saved in the registry, so after restore it gets them wrong), I can see how this can cause issues. I would check the registry key to make sure it point to correct folders, check app data folder, make sure Plex has access to the folder (meaning account under which Plex runs does), and go from there. I have done this multiple times (but not recently), and so did many others, and this is the first time I hear about the issue, so I'm not sure what might have caused it.

@mkitchingh
Copy link
Author

I mean took a plain test machine, and installed Plex. I finished the install. It then tries to start some additional setup and customization questions after you launch Plex the first time. I didn't complete that part. I meant I stopped configuring Plex at that point. I didn't change anything. Both are 64 bit Windows 11 machine. I don't think I have done anything out of the ordinary, and certainly didn't want to do anything special. I will keep poking around.

@mkitchingh
Copy link
Author

It was this registry key. "LocalAppDataPath" The user directory was slightly different on the old computer vs. the new. I fixed that registry key, and Plex starts. It still seems to have non of my config though. The libraries aren't there. Manage Libraries shows no libraires at all. Restore appears clean. See below. I also tried using the -machine flag you mention, but I must not understand where I am supposed to put it. I tried it a command line argument to the restore, and that failed.

PS C:\temp> .\PlexBackup.ps1 -Mode Restore -BackupDirPath "\\10.0.10.10\files$\PlexBackups\20240403103015"
PlexBackup v2.1.7 (c) Alek Davis
Script started at:
  04/08/2024 13:10:33
Operation mode:
  RESTORE
Backup type:
  DEFAULT
Plex version:
  1.40.1.8227
Backup version:
  1.40.1.8227
Stopping Plex services:
  Plex Update Service
Stopping Plex Media Server process:
  Plex Media Server.exe
Restoring Plex app data folders.
Importing registry key file:
  \\10.0.10.10\files$\PlexBackups\20240403103015\3\55284a6f7b667f3761eb0f017c2d891a.reg
Restore operation completed.
Starting Plex services:
  Plex Update Service
Starting Plex Media Server:
  C:\Program Files\Plex\Plex Media Server\Plex Media Server.exe
RUNAS ERROR: Unable to run - C:\Program Files\Plex\Plex Media Server\Plex Media Server.exe
87: The parameter is incorrect.
 Plex app data size:
  137 files and folders
  0 GB of data
Script ended at:
  04/08/2024 13:10:37
Script ran for (hr:min:sec.msec):
  00:00:03.645
Script execution result:
  SUCCESS
Done.

@alekdavis
Copy link
Owner

Okay, first of all, from your backup log file:

Script started at:
  04/01/2024 04:00:00
Operation mode:
  BACKUP
Backup type:
  7ZIP

Now, from you restore log:

Script started at:
  04/08/2024 13:10:33
Operation mode:
  RESTORE
Backup type:
  DEFAULT

If you use 7zip to back up, you need to use 7zip to restore. Otherwise, the script will not find the backup files and will only restore the registry, which we can observe by noting that it did not restore any folders:

Restoring Plex app data folders.
Importing registry key file:
  \\10.0.10.10\files$\PlexBackups\20240403103015\3\55284a6f7b667f3761eb0f017c2d891a.reg
Restore operation completed.

The fact that it shows that there is hardly any data in the app data folder is also a hint:

 Plex app data size:
  137 files and folders
  0 GB of data

So the first thing to try would be to run restore with parameter -Mode 7Zip. To address error 87, you may want to add parameter -Machine x86 or -Machine amd64 (this would depend on the platform version of the PMS executable, which, based on the fact that the PMS folder is under the Program Files and not Program Files (x86) folder, but it may be a wrong assumption.

@alekdavis
Copy link
Owner

I added more sanity checks during restore to capture the situation like yours.

@mkitchingh
Copy link
Author

Got. That makes sense. I didn't know I had to specify that on the restore. I'm sure that is the problem. I'm going to have to hold off testing again. Every time I do this, it is kicking my production plex server out of remote access and causing an issue for my remote user (son at college). I can close this unless you want me to do anything else.

@alekdavis
Copy link
Owner

Sure. I will close it. Let me know if you run into any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants