Created
May 27, 2011 14:35
-
-
Save sakama/995367 to your computer and use it in GitHub Desktop.
db_backup.sh
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 | |
# ---------- 設定 ---------- | |
# バックアップ元のデータベース | |
b_name=xxxxxxxx | |
b_user=xxxxxxxx | |
b_pass=xxxxxxxx | |
# バックアップ先のディレクトリ・ファイル | |
bk_dir=/backup/database/ | |
bk_file=$db_name | |
# 保存する日数 | |
bk_days=7 | |
# ---------- ファイル名を設定 ---------- | |
# タイムスタンプを取得 | |
ts_now=`date +%Y%m%d` | |
ts_old=`date "-d$bk_days days ago" +%Y%m%d` | |
# ファイル名を設定 | |
file_temp=$bk_file.sql | |
file_backup=$bk_file.$ts_now.tar.gz | |
file_remove=$bk_file.$ts_old.tar.gz | |
# ---------- バックアップ処理 ---------- | |
# バックアップ先のディレクトリに移動 | |
cd $bk_dir | |
if [ $? != 0 ]; then | |
echo "Backup directory does not exist." | |
exit 1 | |
fi | |
# データベースをダンプ | |
/usr/bin/mysqldump $db_name -u $db_user -p$db_pass --opt > $file_temp | |
if [ $? != 0 -o ! -e $file_temp ]; then | |
echo "Cannot dump database." | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment