Created
April 22, 2010 13:31
-
-
Save bcalloway/375219 to your computer and use it in GitHub Desktop.
MySQL backup shell script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DATE1=`date | awk '{print $3}'` | |
DATE2=`date | awk '{print $2}'` | |
DATE3=`date | awk '{print $6}'` | |
THEDATE="${DATE1}${DATE2}${DATE3}" | |
########################### CONFIGURATION START | |
ORIGDIR="/home/scullygroup/mysql.bak/" # original directory to put | |
# Main dev db | |
MYSQLHOST=localhost # MySQL Host | |
MYSQLUSER=root # MySQL user for dump | |
MYSQLPASS=XXXXXX # MySQL password for dump | |
DB=mydatabase # DB name | |
BAK=mybackupfile # name of backup file | |
# Offsite server | |
USER=username # user account name | |
DOMAIN=myserverdomain.com # domain of offisite server | |
DIR=backupdirectory # name of backup directory (in user home) | |
########################### CONFIGURATION DONE | |
cd ${ORIGDIR} # chdir to the right dir | |
# Dump the db | |
mysqldump -u ${MYSQLUSER} -p${MYSQLPASS} -h${MYSQLHOST} ${DB} > "./${BAK}_${THEDATE}.sql" | |
tar zcvf ./${BAK}_${THEDATE}.sql.tgz ./${BAK}_${THEDATE}.sql | |
rm -f ./${BAK}_${THEDATE}.sql | |
# Send dump to offsite server | |
#scp ${BAK}_${THEDATE}.sql.tgz ${USER}@#{DOMAIN}:~/${DIR} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment