Created
October 27, 2009 01:53
-
-
Save pgib/219233 to your computer and use it in GitHub Desktop.
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/sh | |
#========================================================================== | |
# RETRIX HOSTING - INTERNAL USE ONLY | |
#========================================================================== | |
# | |
if [ -z $1 ]; then | |
cat << __EOT | |
Usage: $DB_NAME <backup path> <database name> <db user> <db password> | |
If your backup path has a file called <database name>.tables, the script will only backup the tables specified. There should be one line in the file with all of the tables listed with spaces inbetween. | |
__EOT | |
exit | |
fi | |
if [ -x /usr/local/mysql/bin/mysqldump ]; then | |
MYSQLDUMP_CMD="/usr/local/mysql/bin/mysqldump" | |
else | |
MYSQLDUMP_CMD="/usr/local/bin/mysqldump" | |
fi | |
DATE=`date +%Y.%m.%d-%H.%M` | |
TARGET=$1 | |
DB_NAME=$2 | |
DB_USER=$3 | |
if [ ! -z $4 ]; then | |
DB_PASS="-p$4" | |
fi | |
mkdir /tmp/$DB_NAME-$DATE | |
if [ ! -d /tmp/$DB_NAME-$DATE ]; then | |
echo "Could not make temp dir. Aborting..." | |
exit | |
fi | |
cd /tmp/$DB_NAME-$DATE | |
if [ -e $TARGET/$DB_NAME.tables ]; then | |
TABLES=`/usr/bin/head -n 1 $TARGET/$DB_NAME.tables` | |
else | |
TABLES="" | |
fi | |
$MYSQLDUMP_CMD -u $DB_USER $DB_PASS $DB_NAME $TABLES >$DB_NAME-$DATE.txt | |
gzip $DB_NAME-$DATE.txt | |
mv $DB_NAME-$DATE.txt.gz $TARGET 2>/dev/null | |
cd /tmp | |
rm -rf /tmp/$DB_NAME-$DATE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment