MySQL automatic backup script _1

MySQL backup of local e-mail messages script file back_mysql.sh

[root@localhost ~]# cat back_mysql.sh

NowTime=`date +%Y_%m_%d`

preTime=`date +%Y_%m_%d --date="-7 day"`

Directory=/back/mysql

mkdir -p $ Directory                                                   effect # -p is possible to build multi-level directory

-u mysqldump root  -ppasswd EXT mail  > $ Directory / extmail_ $ after NowTime.sql # -u and -p do with the space, if you can back up all the libraries --all-database

Directory -rf $ RM / extmail_ $ pretime.sql                                 # -rf compulsory and gradual delete a file or folder


Script created by default do not have permission, so they need to command their empowerment.

[root@localhost ~]# chmod back_mysql.sh 764


Then add a scheduled task to define a backup once a day, run crontab -e command to add Task Scheduler:

[root@localhost ~]# crontab -e

40 01 * * * /back/mysql/back_mysql.sh


Explanation:

* There is a space between the number of

* 011 * 5 * This "*" means first is minute, in the range 0-59

                            The second is the hour, in the range 0-23

                            The third day is in the range 1-31

                            The fourth is the month, the value range 1-12

                            The fifth is the week, ranging from 0-6 (0 for Sunday)

The above content can already be reached in a day / back / mysql directory automatically back up mailbox username and password information, and can be maintained and the recent record of 7 days a week.

Guess you like

Origin www.cnblogs.com/mylover2/p/11015887.html