Skip to content

Instantly share code, notes, and snippets.

@MorphyDK
Last active April 30, 2022 20:36
Show Gist options
  • Save MorphyDK/249bb38be1e3655b230a2d5ec534a6b6 to your computer and use it in GitHub Desktop.
Save MorphyDK/249bb38be1e3655b230a2d5ec534a6b6 to your computer and use it in GitHub Desktop.
Backup your Plexmediaserver ( incl database )
#!/bin/bash
##SCRIPT TO BACKUP YOUR ENTIRE PLEXMEDIASERVER
##Needs root access
if [ "$(whoami &2>/dev/null)" != "root" ] && [ "$(id -un &2>/dev/null)" != "root" ]
then
echo "You must use root to run this script"
exit 1
fi
if pidof -o %PPID -x "plexbackup.sh"; then
exit 2
fi
LOGFILE="/home/YOURUSERNAMEHERE/logs/plexbackup.log"
CONFIG="/home/YOURUSERNAMEHERE/.config/rclone/rclone.conf"
RCLONE="/usr/bin/rclone"
systemctl stop plexmediaserver
sleep 5
echo "$(date "+%d.%m.%Y %T") Backup of Plexmediaserver is starting.." | tee -a $LOGFILE
cd /var/lib/plexmediaserver
tar cf ${BackupDir}/PlexBackup.tar ./Library
systemctl start plexmediaserver
sleep 5
echo "$(date "+%d.%m.%Y %T") Backup of database is done - starting Plexmediaserver and copying backup to Googledrive.." | tee -a $LOGFILE
# Copy file to Gdrive
sleep 2
$RCLONE copy --config=$CONFIG /PlexBackup.tar Plexbackup: -v -c --transfers=5 --checkers=5 --bwlimit 20M --stats=10s --log-file=$LOGFILE
echo "$(date "+%d.%m.%Y %T") Backup of Plexmediaserver database is completed." | tee -a $LOGFILE
sleep 3
echo "$(date "+%d.%m.%Y %T") Cleaning up - removing local backup file." | tee -a $LOGFILE
rm /PlexBackup.tar
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment