Skip to content

Instantly share code, notes, and snippets.

@MorphyDK
Last active August 17, 2022 12:23
Show Gist options
  • Save MorphyDK/41369e373cf5cd794921c6ec7b93d7a7 to your computer and use it in GitHub Desktop.
Save MorphyDK/41369e373cf5cd794921c6ec7b93d7a7 to your computer and use it in GitHub Desktop.
Restore your Plexmediaserver from Googledrive
#!/bin/bash
##Plexmediaserver restore
##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 "plexrestore.sh"; then
exit 2
fi
LOGFILE="/home/plex/logs/plexrestore.log"
echo "$(date "+%d.%m.%Y %T") Downloading your backup file for restore." | tee -a $LOGFILE
#Copy file from your Googlecrypt to root of the server.
/usr/bin/rclone copy --config=/home/plex/.config/rclone/rclone.conf Plexbackup:PlexBackup.tar / -v -c --transfers=5 --checkers=5 --bwlimit 80M --stats=10s --log-file=$LOGFILE
echo "$(date "+%d.%m.%Y %T") Download of Plexmediaserver database is completed." | tee -a $LOGFILE
sleep 3
echo "Stopping Plexmediaserver to restore database"
systemctl stop plexmediserver
sleep 5
cd /var/lib/plexmediaserver
mv Library Library.old
tar xf ${BackupDir}/PlexBackup.tar
chown -R plex:plex ./Library &
find . -type d -exec chmod 755 {} \; &
find . -type f -exec chmod 644 {} \; &
wait
echo "Restore is complete, starting Plexmediaserver."
systemctl start plexmediaserver
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment