Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Backup databases from bluehost
#!/bin/sh
LOGFILE=/tmp/bluehost_backup.log
EXPECTED_ARGUMENTS=3
exec 6>&1 # Link file descriptor #6 with the standard output
exec > $LOGFILE # stdout sent to $LOGFILE
#Check script arguments
if [ $# -ne $EXPECTED_ARGUMENTS ]
then
echo "No arguments supplied."
echo "Script usage:"
echo " $0 bluehost_db_username bluehost_db_password target_folder"
exit 1
fi
### Edit Me ###
dbUser=$1
dbPass=$2
bluehostUser="youUsername"
yourdomain="yourDomainName"
backups=$3
databases="db1 db2 db3"
### Edit Me ###
old_cd="$(pwd)"
cd "${backups}"
for db in $databases
do
FILE_NAME="${bluehostUser}_${db}_$(date +"%d%m%Y").sql.gz"
echo "Starting backup ${bluehostUser}_${db}: $(date +"%d/%m/%Y %H:%M:%S")"
ssh -C ${bluehostUser}@${yourdomain} "mysqldump --opt --compress -u ${dbUser} --password='${dbPass}' ${bluehostUser}_${db} | gzip -9 -c" > $FILE_NAME
sudo mv ./$FILE_NAME $backups
echo "Backup Completed: $(date +"%d/%m/%Y %H:%M:%S")!"
done
cd "${old_cd}"
exit 0
######
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment