I’ve translated my old post into English version with Italic font type.
這是一個簡單的範例程式,用來備份mysql用的。
This is a simple example program for MySQL backup.
以下假設我的MySQL使用者帳號為user,密碼為123,database名稱為db1
Assume that my MySQL account is user, password is 123 and the database name is db1.
backupmysql.sh:
=Edit the following content=
#!/bin/sh
#Program:
# This code backup MySQL database with date.
# Author: Allen
#History:
# 2009/1/1
#Program:
# This code backup MySQL database with date.
# Author: Allen
#History:
# 2009/1/1
#take date
date=`date +%Y%m%d`
date=`date +%Y%m%d`
#database name
db_name=’db1‘
db_user=‘user“
db_password=’123‘
db_name=’db1‘
db_user=‘user“
db_password=’123‘
mysqldump $db_name -u $db_user –password=”$db_password” > your_backup_directory/$db_name$date.sql
=End of editing =
然後將這支bash程式權限設定為 700 (chmod 700 backupmysql.sh)。
Change permission of this back program into 700 via “chmod 700 backupmysql.sh” command.
如果你要讓它定期幫你備份的話,加入crontab就好囉。
If you want this program do backup procedure periodically, you can add it into crontab.
例如我要讓它每七天都幫我備份的話,只要加入以下:
For example, I want to backup every 7 days, and I just add the following content via “crontab -e” command.
#Allen: Execute backupmysql.sh automatically at 1:00 for every 7 days.
0 1 */7 * * backupmysql.sh
0 1 */7 * * backupmysql.sh