This is a bash script to backup Linux Plex Media Server settings and database, and log the results.
MIT License
This is a bash script to backup Linux Plex Media Server settings and database, and log the results.
The Linux computer's hostname, date, and Plex Media Server version are included in the backup's filename in case you need to roll Plex back to an older version or you save backups from more than one Plex Servers.
Example of the backup's auto-generated filenames:
If you run multiple backups on the same day the time will be included in the filename.
Example of the backup's auto-generated filenames:
You need to set backupDirectory= near the top of the script (below the header). Set it to the location where you want the backup saved to.
Backup_Directory=/share/Backups/Plex_Backups
or
Backup_Directory=/share/folder with spaces/Plex_Backups
The script gets the disto and hostname from the NAS to use logs and backup name. Set Name= to distro, hostname or you can set a 'nickname'. If Name= is blank the Linux computer's hostname will be used.
The LogAll setting enables, or disables, logging every file that gets backed up. Set LogAll= to yes or no. Blank is the same as no.
Name=distro
LogAll=no
Make sure that backup_linux_plex.config and plex_backup_exclude.txt are in the same folder as Linux_Plex_Backup.sh
Note: Due to some of the commands used this script needs to be run by a user in sudo, sudoers or wheel group, or as root
Run the script by a user in sudo, sudoers or wheel group.
sudo -s "/share/scripts/Linux_Plex_Backup.sh"
Issue | Cause | Solution |
---|---|---|
/usr/bin/env: ‘bash\r’: No such file or directory | File has Mac line endings! | Download latest zip file |
Cursor sits there doing nothing | File has Windows line endings! | Download latest zip file |
syntax error near unexpected token | You downloaded the webpage! | Download latest zip file |
If you get a "No such file or directory" error check the following:
sudo -s "/share/folder with spaces/Linux_Plex_Backup.sh"
sudo chmod +x "/share/scripts/Linux_Plex_Backup.sh"
sudo chmod +x "/share/scripts/Restore_Linux_Plex_Backup.sh"
If you run the script with the test argument it will only backup Plex's Logs folder.
sudo -s "/share/scripts/Linux_Plex_Backup.sh" test
If you run the script with the error argument it will only backup Plex's Logs folder and cause an error so you can test the error logging.
sudo -s "/share/scripts/Linux_Plex_Backup.sh" error
To restore Plex from a backup run the included Restore_Linux_Plex_Backup.sh in a shell:
sudo -s "/share/scripts/Restore_Linux_Plex_Backup.sh"
Note: Replace "/share/scripts/" with the path to where Linux Plex Backup's files are located.
The first thing you'll see is a menu listing all of your Plex backups that you created with Linux Plex Backup. Select the backup you want to restore and the sript will do the rest.
Note: I would only restore a backup from the same Plex version as you currently have installed (which is why the Plex version is included in the backup file name and logs.
If you previously ran Linux Plex Backup with the test argument you can run Restore_Linux_Plex_Backup.sh with the test argument so the menu will list any small backups (less than 1 MiB).
sudo -s "/share/scripts/Restore_Linux_Plex_Backup.sh" test
Note: Replace "/share/scripts/" with the path to where Linux Plex Backup's files are located.