The Remote Copy command is usually used to back up data between servers. The scp command can be used to copy data remotely. It also supports local-to-remote copying and remote-to-local copying.
Scp --- copy files back and forth between different Linux systems
Basic scp command format:
Scp [-1246 BCpqrv] [-c cipher] [-F ssh_config] [-I identity_file]
[-L limit] [-o ssh_option] [-P port] [-S program]
[[User @] host1:] file1 [...] [[user @] host2:] file2
Parameters of the scp command:
-1
Force scp command to use protocol ssh1
-2
Force scp command to use protocol ssh2
-4
Force scp command to only use IPv4 addressing
-6
Force scp command to only use IPv6 addressing
-B
Use batch processing mode (no transmission password or phrase is asked during transmission)
-C
Compression is allowed. (Pass the-C flag to ssh to enable the compression function)
-P retains the modification time, access time, and access permission of the original file.
-Q
The transmission progress bar is not displayed.
-R
Recursively copy the entire directory.
-V details display output. Scp and ssh (1) will display the debugging information of the entire process. This information is used to debug connections, verify and configure problems.
-C cipher
Use cipher to encrypt data transmission. This option is passed directly to ssh.
-F ssh_config
Specify an alternative ssh configuration file. This parameter is passed directly to ssh.
-I identity_file
Read the key file used for transmission from the specified file. This parameter is passed directly to ssh.
-L limit
Limits the bandwidth that a user can use, in Kbit/s.
-O ssh_option
If you are used to using the parameter transfer method in ssh_config (5,
-P port should be written in uppercase. port is the port number used for data transmission.
-S program
Specifies the program used for encrypted transmission. This program must be able to understand the options of ssh (1.
Copy from local to remote
Scp/home/daisy/full.tar.gz root@172.19.2.75:/home/root ), copy the directory and add the parameter-r.
Copy from remote to local
Scp root @/172.19.2.75:/home/root/full.tar.gz/home/daisy/full.tar.gz
Example
Generally, the system prompts us to enter the user name and password of the remote server when executing the copy command. This is an obstacle in the automatic execution program because there is no manual intervention. The methods for mutual access between servers that do not require a password are described earlier. For more information, see the previous article. Here we will introduce the scp copy command. Assume that there are two servers A and B, and the IP address of server B is 115.47.169.130. Now you need to set/var/logs/test on server B. copy the log file to the/bak/directory on server. You can run the command on server.
/Usr/bin/scp root@115.47.169.130:/var/logs/test. log/bak/test. log
If you need to copy/bak/test. SQL on server A to the/data/directory of server B, you can execute
/Usr/bin/scp/bak/test. SQL root@115.47.69.130:/data/test. SQL
Speaking of this, if you want to operate on server B, I believe everyone will do it. In addition, if the default port of the remote server is not 22, you can use the-P command to specify the port after scp, for example:
/Usr/bin/scp-P2200 root@115.47.169.130:/var/logs/test. log/bak/test. log