Iii. Remote Backup
We know that FTP commands are usually used to transmit data between two hosts, but they are generally implemented through interaction, that is, you need to manually enter the IP address, user name, and password of the target host. Obviously, this does not meet the requirements of automatic backup. Fortunately, we can achieve our goal by writing a. netrc file. This file must be named. netrc and stored in the user registration directory on the machine where the FTP command is started. The file permission should be disabled for read access by the group or other users. In this way, when a user uses an FTP command, the system will find it in the user's registration directory. if you can find the netrc file, the file will be executed first. Otherwise, the user will be prompted interactively to enter the user name and password.
Before using the FTP command, you should first create a directory on another UNIX machine for backup to accommodate the backup files. The directory created in this document is/pub. It should be noted that, in order to speed up the backup, the transmission rate between the two hosts should be as high as possible, preferably on the same LAN.
The content of the. netrc file is as follows:
Machine host2
# Host2 is the host name used for backup
Login oracle
# Oracle is a user on the backup host
Password oracle
# Oracle user password
Macdef init
# Define a macro named init, which will be executed at the end of the automatic registration process
Bin
# Set the file transmission mode to binary
LCD/backup
# Go to the local working directory/backup
Cd/pub
# Enter the backup host directory/pub
Mput? ?
# Transfer all files in the/backup Directory to the backup host
Bye
# Exit the FTP session Process
After the. netrc file is compiled, run the following command:
Chmod 600. netrc
In this way, the. netrc file can only be accessed by this user.