Skip to content

Instantly share code, notes, and snippets.

@geeknees
Created December 18, 2014 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save geeknees/c8ca431935fc42eb0391 to your computer and use it in GitHub Desktop.
Save geeknees/c8ca431935fc42eb0391 to your computer and use it in GitHub Desktop.
backup
#!/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