[Cialug] Backup script, did I miss anything?
Tom Pohl
tom at tcpconsulting.com
Fri Dec 26 13:28:00 CST 2014
Looks pretty decent!
The only thing I would caution is that the last rsync will delete anything on the remote backup that isn't on the local filesystem (as I'm sure you know). If the local copies were to be deleted inadvertently, you no longer have remote copies either.
If it were me, I'd capture the names of the files you were purging locally during the find steps and use that list of files to delete from the remote server.
-Tom
> On Dec 24, 2014, at 3:23 PM, Rob Cook <rdjcook at gmail.com> wrote:
>
> 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/
> _______________________________________________
> Cialug mailing list
> Cialug at cialug.org
> http://cialug.org/mailman/listinfo/cialug
More information about the Cialug
mailing list