Skip to content

Instantly share code, notes, and snippets.

@pokutuna
Created September 16, 2016 13:32
Show Gist options
  • Save pokutuna/3579bdc20c19048c4441651e5e9a8682 to your computer and use it in GitHub Desktop.
Save pokutuna/3579bdc20c19048c4441651e5e9a8682 to your computer and use it in GitHub Desktop.
#!/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