Skip to content

Instantly share code, notes, and snippets.

@pgib
Created October 27, 2009 01:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pgib/219233 to your computer and use it in GitHub Desktop.
Save pgib/219233 to your computer and use it in GitHub Desktop.
#!/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