Plex fast BACKUP - n05urpr1532-MHA-Team/PTS-Team GitHub Wiki


Table of Contents

  1. Intro
  2. Script


1. Intro

The purpose of this script is to do faster backups of plex database, by using all the CPU resources of the system. This script is particularly useful for systems with several CPUs/cores as it can take advantage of all of them.

The backup is also sent to Google Drive.

In the script below, you just have to replace the variables with your custom paths.

The process is:

  1. Stop the Plex docker

  2. Create the backup and compressed file with tar + pigz

  3. Restart Plex Docker

  4. Send backup to Google Drive

  5. Remove local backup

You can add this script to crontab.

2. Script

# autoplexbackup.sh 
# !/bin/bash

# Automatic Backup Plex and sync to Google Cloud Drive

# Variables
local_backups=/mnt/BACKUPS
remote=gdrive
remote_backups=BACKUPS
useragent="$(cat /var/plexguide/uagent)"

# Stop Plex
sudo docker stop plex
sleep 2s

# Backup Plex database
tar cf - "/opt/appdata/plex" -P | pigz > "$local_backups/$(date +%F-%R)-PlexBackup.tar.gz"
sleep 2s

# Restart Plex
sudo docker start plex
sleep 2s

# Send backup to Google Drive
rclone --config "/opt/appdata/plexguide/rclone.conf" copy "$local_backups" "$remote:$remote_backups" --user-agent="$useragent"

# Remove local backup
rm -rv $local_backups/*

crontab add

sudo sed -i '$a\@weekly bash /the/path/for/script/autoplexbackup.sh\' /var/spool/cron/crontabs/root