Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save anpleenko/56bc322da5ca84f58ae7ef6d2f6b34ee to your computer and use it in GitHub Desktop.

Select an option

Save anpleenko/56bc322da5ca84f58ae7ef6d2f6b34ee to your computer and use it in GitHub Desktop.

Revisions

  1. @ssmereka ssmereka revised this gist Feb 2, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion plexDatabaseBackupScript.sh
    Original file line number Diff line number Diff line change
    @@ -38,7 +38,7 @@ sudo service plexmediaserver stop >> $log 2>&1
    # Backup database
    echo -e "\n\nStarting Backup." >> $log 2>&1
    echo -e "------------------------------------------------------------\n" >> $log 2>&1
    sudo rsync -avn --delete "$plexDatabase" "$backupDirectory" >> $log 2>&1
    sudo rsync -av --delete "$plexDatabase" "$backupDirectory" >> $log 2>&1

    # Restart Plex
    echo -e "\n\nStarting Plex Media Server." >> $log 2>&1
  2. @ssmereka ssmereka revised this gist Feb 2, 2014. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions plexDatabaseBackupScript.sh
    Original file line number Diff line number Diff line change
    @@ -7,18 +7,18 @@
    # Script Tested on:
    # Ubuntu 12.04 on 2/2/2014 [ OK ]

    # Log file for script's output named with
    # the script's name, date, and time of execution.
    scriptName=$(basename ${0})
    log="/srv/raid10/backups/logs/${scriptName}_`date +%m%d%y%H%M%S`.log"

    # Plex Database Location. The trailing slash is
    # needed and important for rsync.
    plexDatabase="/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/"

    # Location to backup the directory to.
    backupDirectory="/srv/raid10/backups/plexmediaserver/database/"

    # Log file for script's output named with
    # the script's name, date, and time of execution.
    scriptName=$(basename ${0})
    log="/srv/raid10/backups/logs/${scriptName}_`date +%m%d%y%H%M%S`.log"

    # Check for root permissions
    if [[ $EUID -ne 0 ]]; then
    echo -e "${scriptName} requires root privledges.\n"
  3. @ssmereka ssmereka revised this gist Feb 2, 2014. 1 changed file with 26 additions and 26 deletions.
    52 changes: 26 additions & 26 deletions plexDatabaseBackupScript.sh
    Original file line number Diff line number Diff line change
    @@ -4,46 +4,46 @@
    # Author Scott Smereka
    # Version 1.0

    # Log the script's output to a file with
    # Script Tested on:
    # Ubuntu 12.04 on 2/2/2014 [ OK ]

    # Log file for script's output named with
    # the script's name, date, and time of execution.
    logFile="\"/srv/raid10/backups/logs/`basename ${0}`_`date +%m%d%y%H%M%S`.log\""
    scriptName=$(basename ${0})
    log="/srv/raid10/backups/logs/${scriptName}_`date +%m%d%y%H%M%S`.log"

    # Plex Database Location. The trailing slash is
    # needed and important for rsync.
    plexDatabase="\"/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/\""
    plexDatabase="/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/"

    # Location to backup the directory to.
    backupDirectory="\"/srv/raid10/backups/plexmediaserver/database/\""

    # Log a command, used at the end of a command
    # to store its output to the log file.
    LOG=">> $logFile 2>&1"
    backupDirectory="/srv/raid10/backups/plexmediaserver/database/"

    # Check for root permissions
    if [[ $EUID -ne 0 ]]; then
    echo -e "${scriptName} requires root privledges.\n"
    echo -e "sudo $0 $*\n"
    exit 1
    fi

    # Create Log
    echo -e "Staring Backup of Plex Database." > $logFile
    echo -e "------------------------------------------------------------\n" $LOG

    # Check for debug mode, in which case
    # tail the log file's output for the user.
    if [[ $* == *--debug*]]; then
    tail -f $logFile
    fi
    echo -e "Staring Backup of Plex Database." > $log 2>&1
    echo -e "------------------------------------------------------------\n" >> $log 2>&1

    # Stop Plex
    echo -e "\n\nStopping Plex Media Server." $LOG
    echo -e "------------------------------------------------------------\n" $LOG
    sudo service plexmediaserver stop $LOG
    echo -e "\n\nStopping Plex Media Server." >> $log 2>&1
    echo -e "------------------------------------------------------------\n" >> $log 2>&1
    sudo service plexmediaserver stop >> $log 2>&1

    # Backup database
    echo -e "\n\nStarting Backup." $LOG
    echo -e "------------------------------------------------------------\n" $LOG
    sudo rsync -av --delete $plexDatabase $backupDirectory $LOG
    echo -e "\n\nStarting Backup." >> $log 2>&1
    echo -e "------------------------------------------------------------\n" >> $log 2>&1
    sudo rsync -avn --delete "$plexDatabase" "$backupDirectory" >> $log 2>&1

    # Restart Plex
    echo -e "\n\nStarting Plex Media Server." $LOG
    echo -e "------------------------------------------------------------\n" $LOG
    sudo service plexmediaserver start $LOG
    echo -e "\n\nStarting Plex Media Server." >> $log 2>&1
    echo -e "------------------------------------------------------------\n" >> $log 2>&1
    sudo service plexmediaserver start >> $log 2>&1

    # Done
    echo -e "\n\nBackup Complete." $LOG
    echo -e "\n\nBackup Complete." >> $log 2>&1
  4. @ssmereka ssmereka created this gist Feb 2, 2014.
    49 changes: 49 additions & 0 deletions plexDatabaseBackupScript.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    #!/bin/bash

    # Backup a Plex database.
    # Author Scott Smereka
    # Version 1.0

    # Log the script's output to a file with
    # the script's name, date, and time of execution.
    logFile="\"/srv/raid10/backups/logs/`basename ${0}`_`date +%m%d%y%H%M%S`.log\""

    # Plex Database Location. The trailing slash is
    # needed and important for rsync.
    plexDatabase="\"/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/\""

    # Location to backup the directory to.
    backupDirectory="\"/srv/raid10/backups/plexmediaserver/database/\""

    # Log a command, used at the end of a command
    # to store its output to the log file.
    LOG=">> $logFile 2>&1"


    # Create Log
    echo -e "Staring Backup of Plex Database." > $logFile
    echo -e "------------------------------------------------------------\n" $LOG

    # Check for debug mode, in which case
    # tail the log file's output for the user.
    if [[ $* == *--debug*]]; then
    tail -f $logFile
    fi

    # Stop Plex
    echo -e "\n\nStopping Plex Media Server." $LOG
    echo -e "------------------------------------------------------------\n" $LOG
    sudo service plexmediaserver stop $LOG

    # Backup database
    echo -e "\n\nStarting Backup." $LOG
    echo -e "------------------------------------------------------------\n" $LOG
    sudo rsync -av --delete $plexDatabase $backupDirectory $LOG

    # Restart Plex
    echo -e "\n\nStarting Plex Media Server." $LOG
    echo -e "------------------------------------------------------------\n" $LOG
    sudo service plexmediaserver start $LOG

    # Done
    echo -e "\n\nBackup Complete." $LOG