1.給mysql創(chuàng)建用戶備份的角色,并且授予角色select, reload, show databases, lock tables等權(quán)限。
mysql> create user 'backuper'@'localhost' identified by '********'; Query OK, 0 rows affected (0.00 sec) mysql> grant SELECT, RELOAD, SHOW DATABASES, LOCK TABLES on *.* to backuper@localhost; Query OK, 0 rows affected (0.00 sec)
2.在系統(tǒng)中找到存儲空間比較大的硬盤創(chuàng)建備份目錄,并且創(chuàng)建shell腳本
[root@qxyw backup]# vim backup_qianyu_veeker_db.sh #!/bin/bash mysqldump -ubackuper -p******** qianyu_veeker_db > /home/mysql/backup/qianyu_veeker_db_$(date +%Y%m%d_%H%M%S).sql
注意:-u和用戶名中間是沒有空格的,-p和密碼也是這樣的。
3.添加計劃任務,需要安裝crontab
vixie-cron 軟件包是 cron 的主程序;
crontabs 軟件包是用來安裝、卸裝、或列舉用來驅(qū)動 cron 守護進程的表格的程序。
[root@qxyw ~]# yum -y install vixie-cron [root@qxyw ~]# yum -y install crontabs
4.設置開機啟動
[root@qxyw ~]# chkconfig --level 345 crond on
5.修改/etc/crontab文件,添加需要周期執(zhí)行的任務
[root@qxyw etc]# vim crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root HOME=/# For details see man 4 crontabs # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | |# * * * * * user-name command to be executed0 0 * * * /home/mysql/backup/backup_qianyu_veeker_db.sh
6.啟動crontab服務
[root@qxyw etc]# service crond start Starting crond: [ OK ]
?,
? 版權(quán)聲明
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載。
THE END