1. In order to use SCP without entering a password, another SSH key pair is used for verification.
1. Use the ssh-keygen command to generate a key. In addition to the password, select the default value: Press enter.
[Root @ xxx root] # ssh-keygen-T RSA
Generating public/private RSA key pair.
Enter file in which to save the key (/root/. Ssh/id_rsa ):
Created directory '/root/. Ssh '.
Enter passphrase (empty for no passphrase ):
Enter same passphrase again:
Your identification has been saved in/root/. Ssh/id_rsa.
Your public key has been saved in/root/. Ssh/id_rsa.pub.
The key fingerprint is:
E0: F0: 3B: D3: 0a: 3D: da: 42: 01: 6a: 61: 2f: 6C: A0: C6: E7 root @ xxx
[Root @ xxx root] #
2. Change the public key access attribute in this key pair to 755, copy it to the backup machine, and change it to authorized_keys.
[Root@ Xxx Root] #Chmod 755/root/. Ssh/id_rsa.pub [Root @ Xxx Root ] # SCP/root/. Ssh/id_rsa.pub 192.168.1.92:/root/. Ssh/authorized_keys
Root @ xxx's password:
Id_rsa.pub 100 % 218 3 . 2 Mb/s 00 : 00
[Root @ Xxx Root ] #
Then, you do not need to enter a password when accessing the machine using ssh scp sftp. In this way, you can use shell for automatic file transfer.
Ii. Write the backup script VI/root/crontabshell/bakdb. Sh
My_current_date = 'Date + % Y-% m-% d: % H: % m: % s'
/Usr/local/MySQL/bin/mysqldump-phereismysqlpassword applicationdb>/bakup_data/applicationdb _ " $ My_current_date " _Dump.txt
/Usr/local/MySQL/bin/mysqldump-phereismysqlpassword webappdb>/bakup_data/webappdb _ " $ My_current_date " _Dump.txt
SCP/bakup_data/applicationdb _ " $ My_current_date " _Dump.txt root @ 192.168.1.92 :/Bakup_data
SCP/bakup_data/webappdb _ " $ My_current_date " _Dump.txt root @ 192.168.1.92 :/Bakup_data
3. automatically execute the schedule and execute crontab-e
0 0 * **/Root/crontabshell/bakdb. Sh
You can test it and change 0 to 10 minutes after the current time.
Be sure not to change it to 5 minutes after the current time, and sometimes it may not be executed.