Considering that data is backed up on the local machine, once the machine's hard disk fails, the data cannot be taken out. Remote manual data backup is time-consuming and time-consuming. The best way is to use scripts to implement remote automatic mutual backup. However, a password is required for remote login through SSH or file copying through SCP. To overcome this problem, you first need to implement SSH login without a password, so that you can use rsync, SCP, rexec and other commands for remote backup. 1. Set SSH login without a password. The method is as follows: Assume that the server a and server B needs to log on to server B with root instead of entering the password on server a. follow these steps: 1) generate a key pair on machine A and execute the following command: Ssh-keygen-T RSA Generating public/private RSA key pair. Enter file in which to save the key (/root/. Ssh/id_rsa):/root/. Ssh/id_rsa Enter passphrase (empty for no passphrase): Press ENTER Enter same passphrase again: Press ENTER 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: F6: 61: A8: 27: 35: Cf: 4C: 6d: 13: 22: 70: Cf: 4C: C8: A0: 23 root @ host1 In this way, id_rsa and id_rsa.pub are generated under the/root/. Ssh/path, where id_rsa is the key and id_rsa.pub is the public key. 2) Copy id_rsa.pub generated on machine A to machine B. Assume that it is copied to the temporary directory of machine B, for example: SCP/root/. Ssh/id_rsa.pub root@218.242.214.20:/tmp 3) log on to machine B with the root account, go to its home directory, create the authorized_keys file, and set the permissions. Cd ~ /. SSH CAT/tmp/id_rsa.pub> authorized_keys Chmod 400 authorized_keys Rm-F/tmp/id_rsa.pub 4) test Go to the root account on machine A and try to log on to machine B. Check if the password is not required. Note: The authorized_keys File Permission is very important. If it is set to 777, you still need to provide a password when logging on. Remember to delete id_rsa.pub in the temporary directory to make it a good habit. This method is successfully tested on red hat9.0. 2. Edit the crontab file VI/etc/crontab For example, set to execute the script in cron. daily at every day: 00 3 *** root run-parts/etc/cron. daily 3. Edit the script in cron. daily. CD/etc/cron. daily/ VI backupdb Pg_dump-u Postgres voipack>/voipack. SQL Pg_dump-u Postgres regserver>/regserver. SQL Tar-cvjf/aavm.tgz.bz2/usr/local/aavm Tar-cvjf/oracle.tgz.bz2/var/Oracle SCP/voipack. SQL root@218.242.214.20:/root/218.242.214.23 _ backup SCP/regserver. SQL root@218.242.214.20:/root/218.242.214.23 _ backup SCP/aavm.tgz.bz2 root@218.242.214.20:/root/218.242.214.23 _ backup SCP/oracle.tgz.bz2 root@218.242.214.20:/root/218.242.214.23 _ backup Copy the backup file generated on 23 to the path 218.242.214.20:/root/218.242.214.23 _ backup. In the same way, data on server B can be backed up to server a to implement dual-host mutual backup. |