Last active
December 16, 2015 02:28
-
-
Save ain/5362273 to your computer and use it in GitHub Desktop.
mysqldump a database to gzip
This file contains hidden or 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 | |
usage="Usage: mysqldumpgz database_name username" | |
err[1]="Invalid command" | |
# Check for database name argument | |
if [ -z "$1" ] | |
then | |
echo ${err[1]} | |
echo "$usage" | |
exit 1 | |
else | |
db_name=$1 | |
fi | |
# Check for username argument | |
if [ -z "$2" ] | |
then | |
echo ${err[1]} | |
echo "$usage" | |
exit 1 | |
else | |
username=$2 | |
fi | |
`mysqldump ${db_name} --single-transaction -u ${username} -p | gzip -c | cat > ${db_name}-$(date +%Y%m%d%H%M%S).sql.gz` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tip: decompress with
gzip -dv [filepath]