Created
December 18, 2014 11:00
-
-
Save geeknees/c8ca431935fc42eb0391 to your computer and use it in GitHub Desktop.
backup
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 | |
# バックアップファイルを何日分残しておくか | |
period=7 | |
# バックアップファイルを保存するディレクトリ | |
dirpath='/home/user/backup_mysql/sql' | |
# ファイル名を定義(※ファイル名で日付がわかるようにしておきます) | |
filename=`date +%y%m%d` | |
# mysqldump実行 | |
/usr/bin/mysqldump --opt -u [USER名] --password=[パスワード] [DATABAE名] > $dirpath/$filename.sql | |
# パーミッション変更 | |
chmod 700 $dirpath/$filename.sql | |
# 古いバックアップファイルを削除 | |
oldfile=`date --date "$period days ago" +%y%m%d` | |
echo old file is $oldfile | |
rm -f $dirpath/$oldfile.sql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment