[Cialug] Backup script, did I miss anything?

Rob Cook rdjcook at gmail.com
Wed Dec 24 15:23:41 CST 2014


I worked up a backup script for a website that I help with, I wanted to
have local and offsite backups just in case. I've tested the script and
everything works for me now but I just wanted another set of eyes to take a
look and see if I missed something.

Thanks,

Rob Cook

#!/bin/bash
#Define variables belowTIME=`date +%b-%d-%y`                   # This
command will add date in backup file name.
#WordpressWPFILENAME="websitewphtml"                # This defines the
Wordpress backup file name.WPSRCDIR="/var/www/html/"               #
Location of Wordpress dataDESDIR="/opt/backup"                    #
Destination of all backup files.
#MySQLMYSQLUSER="something"                   # MySQL
usernameMYSQLPASSWORD="somethingelse"           # MySQL
passwordMYSQLHOST="localhost"                   # MySQL
hostnameMYSQLDBNAME="yetanotherthing"           # MySQL database name
#LoggingLOG="/opt/backup/$WPFILENAME-$TIME.log"LOGSQL="/opt/backup/$MYSQLDBNAME-$TIME.log"
#Actual backing up of things below
tar -cvpzf $DESDIR/$WPFILENAME-$TIME.tar.gz $WPSRCDIR 2>&1 >> $LOG
mysqldump -v --user=$MYSQLUSER --password=$MYSQLPASSWORD
--host=$MYSQLHOST $MYSQLDBNAME > $DESDIR/$MYSQLDBNAME-$TIME.sql 2>
$LOGSQL
#Locate backups & logs more than 14 days old and delete them
find /opt/backup/websitewphtml-*.tar.gz -maxdepth 1 -type f -mtime +14 -delete
find /opt/backup/yetanotherthing-*.sql -maxdepth 1 -type f -mtime +14 -delete
find /opt/backup/*.log -maxdepth 1 -type f -mtime +14 -delete
#rsync backups to remote server
rsync -avplm --delete --ignore-existing /opt/backup/ -e "ssh -p NOT22"
SSHKEY at REMOTEIPADDRESS:/opt/backup/


More information about the Cialug mailing list