Created
September 16, 2016 13:32
-
-
Save pokutuna/3579bdc20c19048c4441651e5e9a8682 to your computer and use it in GitHub Desktop.
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 | |
# 思考停止で gzip にしつつ mysqldump でテーブルをバックアップしたりレストアしたりするぞ | |
if [ $# != 2 ]; then | |
echo 'tablebackup.sh backup TABLE' | |
echo 'tablebackup.sh restore DUMP.sql' | |
exit 1; | |
fi | |
set -ex | |
# TODO DB名など本番用に調整してデフォルト値いれる | |
MYSQL_USER=${MYSQL_USER:-isucon} | |
MYSQL_PASSWD=${MYSQL_PASSWD:-isucon} | |
DB=${DB:-isucon5q} | |
NOW=$(date "+%Y%m%d_%H%M%S") | |
if [ $1 == 'backup' ]; then | |
mysqldump --default-character-set=binary -u$MYSQL_USER -p$MYSQL_PASSWD $DB $2 | gzip -c > $2_$NOW.sql.gz | |
elif [ $1 == 'restore' ]; then | |
zcat $2 | mysql -u$MYSQL_USER -p$MYSQL_PASSWD $DB | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment