DEV Community

Adam.S
Adam.S

Posted on • Edited on • Originally published at bas-man.dev

Back up your Plex Media Server on Mac OS

The Challenge:

How to automate the backing up of my Plex Media Server

Solution:

A Bash Script

I wanted to automate this process. If I didn't, it probably wouldn't get done.

This script was adapted from another GitHub Gist that I found here.

You will probably need to modify the following variables.

  • plexDatabase
  • plexPlistFile
  • backupDirectory

Pay attention to lines 17 ~ 21. These refer to the possibility that your script may not
complete if your machine can go to sleep. As it suggests use the 'caffeinate' command to prevent
your machine from sleeping during backup. It will be able to sleep after the script completes.

Don't forget to give the script execution permission using 'chmod +x scriptname'

Install a cronjob under your user account using:

  crontab -e
Enter fullscreen mode Exit fullscreen mode

The contents of my cronjob

SHELL=/bin/bash
06 02 * * Sun /usr/bin/caffeinate $HOME/bin/plexbackup.sh
Enter fullscreen mode Exit fullscreen mode

Notes:

  • You need a SHELL set for the cronjob to run the command.
  • The script runs weekly on Sunday from 6:02am
  • It uses caffeinate so that the machine does not sleep during backup. I do not have my sleep value set to 0 on this machine.
  • My backup script is located in my home directory under the folder bin

Top comments (0)