Tuesday, November 16, 2010

Settup schedule backup mysql

(Blog) - Sưu tầm các cách Schedule backup mysql

1. Tạo script file backup trên localhost
a. Window server:
Dùng notepad tạo file *.bat với nội dung sau:

set DATET=%date:~10,4%_%date:~4,2%_%date:~7,2%
"d:\xampp\mysql\bin\mysqldump" --host="localhost" --user="root" --password="" DATABASE > "D:\"backup_database_%DATET%.sql
#pause

Sau đó, tạo Schedule Tasks trong Control Panel

Note:
Year (YYYY)%date:~10,4% or  %date:~12,2% (2 digits: YY)
Month (MM)%date:~4,2%
Day (DD)%date:~7,2%
Hour (HH)%time:~0,2%
Minute (MM)%time:~3,2%
Second (SS)%time:~6,2%
Milisecond%time:~9,2%



2. Linux server:
Từ command line, edit crontab trên linux
# crontab -e

15 2 * * * root mysqldump -u root -pPASSWORD --all-databases | gzip > /backup/database_`data ' %m-%d-%Y'`.sql.gz


Note: Các option cho * * * * *
FieldMeaning
1Minute (0-59)
2Hour (2-24)
3Day of month (1-31)
4Month (1-12, Jan, Feb, etc)
5Day of week (0-6) 0 = Sunday, 1 = Monday etc or Sun, Mon, etc)
6User that the command will run as
7Command to execute


2. Dùng Mysql Administrator

Dùng Mysql Administrator trong bộ Mysql GUI Tools (Download tại http://dev.mysql.com/downloads/gui-tools/5.0.html)
Mysql Administrator
Tab Backup - Schedule

No comments:

Post a Comment