First two servers can login without password (This method is relatively simple, of course, the safety factor will be reduced)
#Ssh-keygen -t rsa# generate key to send to remote server #ssh-copy-ID ~/root/id_rsa.pub [email protected ]
You don't have to enter a password when you ssh. It is also convenient for the task of Crontab, which is scheduled to run automatically.
Now is the script that writes the shell backup SQL to the remote server:
#!/bin/SHdb_name1=""Db_user=""Db_pass=""Bck_dir="/root/backup"DATE=`Date+%F ' mysqldump-u$db_user $DB _name1 > $BCK _dir/db_"$DB _name1"_"$DATE". SqlNAME1= $BCK _dir/db_"$DB _name1"_"$DATE". SQLSCP$NAME 1 [email protected]172.16.253.120:/home/rainsun/BackupRM-RF $NAME 1
Then is CRONTAB-E write timing, here to crontab format do a simple explanation:
Crontab Format Description
We can add the command to execute with CRONTAB-E. The result of the command execution, either standard output or error output, is sent to the user in the form of a message.
The added command must be in the following format:
* * * * * */command path
The first five fields can take an integer value, specify when to start working, and the sixth field is a string, the command field, which includes the commands that the crontab dispatch executes. Each field is segmented with spaces and tabs.
The first 5 fields indicate:
Minutes: 0-59
Hours: 1-23
Date: 1-31
Month: 1-12
Week: 0-6 (0 = Sunday)
You can also use some special symbols:
*: Indicates any moment
,: Represents the Split
-: Represents a segment, as in the second end: 1-5, which means 1 to 5 points
/N: Indicates that each n unit executes once, as in the second paragraph, */1, which indicates that the command is executed every 1 hours. Can also be written as 1-23/1.
Some examples:
XX 8,12,16 * * */data/app/scripts/monitor/df.sh
2 * * */data/app/scripts/hotbackup/hot_database_backup.sh
Ten 8,12,16 * * */data/app/scripts/monitor/check_ind_unusable.sh
Ten 8,12,16 * * */data/app/scripts/monitor/check_maxfilesize.sh
Ten 8,12,16 * * */data/app/scripts/monitor/check_objectsize.sh
43 21 * * * 21:43 execution
15 05 * * * 05:15 execution
0 17 * * * 17:00 execution
0 17 * * 1 per Monday of 17:00 executions
0,10 17 * * 0,2,3 executed every Sunday, Tuesday, Wednesday of 17:00 and 17:10
0-10 17 1 * * Every month 1st from 17:00 to 7:10 each 1-minute execution
0 0 1,15 * 1 each month 1st and 15th and a day of 0:00 execution
42 4 1 * * Every month 1st 4:42 minutes execution
0 21 * 1-6 weeks one to Saturday 21:00 execution
0,10,20,30,40,50 * * * * * every 10 minutes
*/10 * * * * * every 10 minutes
* 1 * * * * Every 1 minutes from 1:0 to 1:59
0 1 * * * 1:00 execution
0 */1 * * * 0 minutes every 1 hours
0 * * * * 0 minutes every 1 hours
2 8-20/3 * * * 8:02,11:02,14:02,17:02,20:02 execution
30 5 1,15 * * 1st and 15th of 5:30 execution
As for how to write crontab depending on the importance of your task
OPS little thing: Back up SQL to the remote server every day