sudo mkdir /scripts
sudo mkdir /backups
#!/bin/bash
#Purpose = Backup of Important Data - Level 0
#Created on 28-02-2016
#Modified on 2016-11-01
#Author = Hafiz Haider
#Contributor = Adam Linkous
#Version 2.1
#START
FILENAME=plexserverbackup-full.tar.gz # Here i define Backup file name format.
SRCDIR=/var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server/ # Location of Important Data Directory (Source of backup).
DESDIR=/backups # Destination of backup file.
SNF=/var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server/plexdata.snar # Snapshot file name and location
EXCLDCRSH=/var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server/Crash\ Reports # Exclude Crash directory
EXCLDLOG=/var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server/Logs # Exclude Logs directory
rm -f "$SNF" > /dev/null # remove any previous snapshots
tar -cvf "$DESDIR"/"$FILENAME" -g "$SNF" "$SRCDIR" --exclude="$EXCLDCRSH" --exclude="$EXCLDLOG" # Backup Command
cp "$SNF" "$SNF".bak # Create copy of full snapshot
#END
#!/bin/bash
#Purpose = Backup of Important Data - Level 1
#Created on 28-02-2016
#Modified on 2016-11-01
#Author = Hafiz Haider
#Contributor = Adam Linkous
#Version 2.1
#START
FILENAME=plexserverbackup-incremental.tar.gz # Here i define Backup file name format.
SRCDIR=/var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server/ # Location of Important Data Directory (Source of backup).
DESDIR=/backups # Destination of backup file.
SNF=/var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server/plexdata.snar # Snapshot file name and location
EXCLDCRSH=/var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server/Crash\ Reports # Exclude Crash directory
EXCLDLOG=/var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server/Logs # Exclude Logs directory
cp "$SNF".bak "$SNF" # Ensure snapshot is copy of full
tar -cvf "$DESDIR"/"$FILENAME" -g "$SNF" "$SRCDIR" --exclude="$EXCLDCRSH" --exclude="$EXCLDLOG" # Backup Command
#END
sudo vi /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
# perform full backup every 2 weeks at 1:00am
0 1 0-28/14 * * root /scripts/plexserverbackup_full.sh
# perform incremental backup every night at 1:05am
5 1 * * * root /scripts/plexserverbackup_incremental.sh
sudo rm -rf /var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server/
sudo tar -xzpf /backups/plexserverbackup-full.tar.gz
sudo tar --incremental -xzpf /backups/plexserverbackup-incremental.tar.gz
- https://support.plex.tv/hc/en-us/articles/201539237-Backing-Up-Plex-Media-Server-Data
- http://broexperts.com/how-to-backup-files-and-directories-in-linux-using-tar-cron-jobs/
- http://broexperts.com/how-to-perform-incremental-backup-in-linux-using-tar-utility/
- http://paulwhippconsulting.com/blog/using-tar-for-full-and-incremental-backups/
- https://www.centos.org/docs/5/html/5.2/Deployment_Guide/s2-autotasks-cron-configuring.html