Plesk2Dropbox is a script I created that will take your most recent Plesk server backup, create a single TAR file, and then uploads that TAR file to Dropbox using the day of the week as the name. This allows you to create a cron job at any interval greater than 24 hours. If you do a nightly backup there will be a file for each day of the week in your Dropbox backup folder.
Plesk has an extension that allows you to do a nightly backup of an individual account or the whole server to Dropbox. I found that it was impossible to do anything but a nightly backup using this setup and the full server backups never successfully uploaded to Dropbox.
Filenames will resemble: Saturday.tar, Monday.tar, etc.
Usage: plesk2dropbox-backup.sh [-v : Verbose Mode] [-r : Run Backup] [-s : Dropbox Status] [-h: Display Help] -v : Displays a detailed output of settings and verifies all folders exist. -r : Runs the script. If running in a cron job you will need to run this argument. -s : Checks the current status of any Dropbox uploads and downloads. -h : Displays this help page. |
- A backup file will not be created unless you use the -r option.
- Run the -v option to verify your configuration is correct before attempting to use the -r option.
- Make sure you verify lines #35 and #38 to ensure they are compatible with your system configuration.
- You must have Dropbox installed and configured prior to running this script.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | #!/bin/bash # --------------------------------------------------------------------------- # # Copyright 2014 # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License at for # more details. # # Usage: plesk2dropbox-backup.sh [-v : Verbose Mode] [-r : Run Backup] [-s : Dropbox Status] [-h : Display Help] # # Revision history: # 0.1 - Initial version # 0.2 - Changed from dash to bash and converted echo strings. # Set TERM environment variable to avoid error message in Cron job. # Added ability to check the status of uploading your current backup. # 0.3 - Adjusted path to be compatible with CentOS. # # 09-27-2014 Created by Brian Aldridge - www.BiteOfTech.com # --------------------------------------------------------------------------- export TERM=${TERM:-dumb} PROGNAME=${0##*/} #Grab path that is compatible with various distros. PRODUCT_ROOT_D=`grep PRODUCT_ROOT_D /etc/psa/psa.conf | awk '{print $2}'` #Setting colors for display. red="\033[31m";yellow="\033[33m";green="\033[32m";nocolor="\033[0m" #Finds the day of the week. currentday="$(date +"%A")" #Change to the temporary folder to store your backup file. backuplocation="/var/backups" #CHANGEME #Location of your Dropbox Backup Folder dropboxfolder="/root/Dropbox/Backups" #CHANGEME #This is the usual location of the Plesk backup files. backupsource="/var/lib/psa/dumps" #Finds the most recent server backup created in Plesk. currentbackup="$(ls -Art $backupsource/*.xml | tail -n 1)" #Gets just the filename for display purposes. backupname="$(ls -1 $currentbackup | sed 's/^.*\///')" #Displays Help usage() { echo -e "Usage: $PROGNAME [${red}-v${nocolor} : Verbose Mode] [${red}-r${nocolor} : Run Backup] [${red}-s${nocolor} : Dropbox Status] [${red}-h${nocolor}: Display Help]" } #Catch options while getopts "vrsh" opt; do case $opt in (v) #Check if Backup Location directory exists if [ -d $backuplocation ]; then echo -e "${green}SUCCESS:${nocolor} The Backup Location directory exists" else echo -e "${red}ERROR:${nocolor} The Backup Location directory does not exist" fi #Check if Backup Source directory exist if [ -d $backupsource ]; then echo -e "${green}SUCCESS:${nocolor} The Backup Source directory exists" else echo -e "${red}ERROR:${nocolor} The Backup Source directory does not exist" fi #Check if Dropbox Backup directory exist if [ -d $dropboxfolder ]; then echo -e "${green}SUCCESS:${nocolor} The Dropbox Backup directory exists" else echo -e "${red}ERROR:${nocolor} The Dropbox Backup directory does not exist" fi #Information output echo ;echo -e "The backup named ${yellow}$backupname${nocolor} will be exported to DropBox under the filename ${yellow}$currentday.tar${nocolor}";echo echo -e "Current Backup : "${red}$currentbackup${nocolor} echo -e "Backup Name : "${red}$backupname${nocolor} echo -e "Backup Location : "${red}$backuplocation${nocolor} echo -e "Backup Source : "${red}$backupsource${nocolor} echo -e "Dropbox Folder : "${red}$dropboxfolder${nocolor} echo -e "Current Day : "${red}$currentday${nocolor};echo #Removing --no-gzip did not seem to shrink the filesize of the backup. echo -e "Example Output: ${yellow}/usr/bin/perl $PRODUCT_ROOT_D/admin/bin/plesk_agent_manager export-dump-as-file --dump-file-name=$currentbackup --output-file=$backuplocation/$currentday.tar --no-gzip${nocolor}" #.gz is not on the end of the file since this is not gzipped. echo -e "Example Output: ${yellow}mv -f $backuplocation/$currentday.tar $dropboxfolder/${nocolor}";echo ;; (r) echo -e "Exporting backup to TAR file." /usr/bin/perl $PRODUCT_ROOT_D/admin/bin/plesk_agent_manager export-dump-as-file --dump-file-name=$currentbackup --output-file=$backuplocation/$currentday.tar --no-gzip echo -e "Export done." echo -e "Copying file to Dropbox." mv -f $backuplocation/$currentday.tar $dropboxfolder/ echo -e "Copy done." ;; (s) echo -e "Checking the status of Dropbox." dropbox status ;; (h) usage echo echo -e " ${red}-v${nocolor} : ${yellow}Displays a detailed output of settings and verifies all folders exist.${nocolor}" echo -e " ${red}-r${nocolor} : ${yellow}Runs the script. If running in a cron job you will need to run this argument.${nocolor}" echo -e " ${red}-s${nocolor} : ${yellow}Checks the current status of any Dropbox uploads and downloads.${nocolor}" echo -e " ${red}-h${nocolor} : ${yellow}Displays this help page.${nocolor}";echo echo -e "This script was developed by Brian Aldridge. For updates and contact information please visit http://www.BiteOfTech.com" ;; (?) echo -e "Invalid Option" usage exit;; esac done # Checking for no attribute. if [ -z "$1" ] then usage exit 1 fi |