[Operation and maintenance] Linux cross-server copy file folder

[Operation and maintenance] Linux cross-server copy file folder

If it is a cloud service, it is recommended to use the intranet ip

scp is the abbreviation of secure copy, which is used to remotely copy files under Linux. The command similar to it is cp, but cp is only copied on the local machine and cannot be cross-server, and scp transmission is encrypted. Might affect speed a little bit. When your server hard disk becomes a read-only system, using scp can help you move the files out. In addition, scp is very resource-intensive and will not increase the system load much. In this regard, rsync is far behind it. Although rsync is faster than scp, when there are many small files, rsync will cause very high hard disk I/O, while scp basically does not affect the normal use of the system.

1. Command format:
scp [parameter] [original path] [target path]

2.Command function:
scp is the abbreviation of secure copy, and scp is a secure remote file copy command based on ssh login under the linux system. The scp command of linux can copy files and directories between linux servers.

3. Command parameters:
-1 force scp command to use protocol ssh1
-2 force scp command to use protocol ssh2
-4 force scp command to use only IPv4 addressing
-6 force scp command to use only IPv6 addressing
-B use batch mode (do not ask for transfer password or phrase during transfer)
-C enable compression. (Pass the -C flag to ssh to turn on compression)
-p Keep the modification time, access time and access permissions of the original file.
-q Do not display the transfer progress bar.
-r Copies entire directories recursively.
-v Display output in verbose mode. scp and ssh(1) will display debugging information for the entire process. This information is used to debug connection, authentication and configuration issues.
-c cipher Encrypt data transmission with cipher, this option will be passed directly to ssh.
-F ssh_config specifies an alternate ssh configuration file, this parameter is passed directly to ssh.
-i identity_file reads the key file used for transmission from the specified file, this parameter is passed directly to ssh.
-l limit Limits the bandwidth that users can use, in Kbit/s.
-o ssh_option If you are accustomed to using the parameter passing method in ssh_config(5),
-P port Note that it is an uppercase P, port is the port number used for specifying data transmission
-S program specifies the program used for encrypted transmission. The program must understand ssh(1) options.

4. Example of use:
Overview of the actual application of the scp command:
copy from a local server to a remote server:

(1) Copy files:
command format:


the code is as follows:
scp local_file remote_username@remote_ip:remote_folder
or
scp local_file remote_username@remote_ip:remote_file
or
scp local_file remote_ip:remote_folder
or
scp local_file remote_ip:remote_ file
第1,2个指定了用户名,命令执行后需要输入用户密码,第1个仅指定了远程的目录,文件名字不变,第2个指定了文件名
第3,4个没有指定用户名,命令执行后需要输入用户名和密码,第3个仅指定了远程的目录,文件名字不变,第4个指定了文件名

(2) 复制目录:
命令格式:
scp -r local_folder remote_username@remote_ip:remote_folder
或者
scp -r local_folder remote_ip:remote_folder
第1个指定了用户名,命令执行后需要输入用户密码;
第2个没有指定用户名,命令执行后需要输入用户名和密码;
从远程服务器复制到本地服务器:
从远程复制到本地的scp命令与上面的命令雷同,只要将从本地复制到远程的命令后面2个参数互换顺序就行了。

复制本地目录到远程服务器

scp -r  /opt/soft/  [email protected]:/opt/soft/


Example 1: Copy files from a remote location to a local directory
Command: scp [email protected]:/opt/soft/nginx.tar.gz /opt/soft/

也可以考虑

rsync 

Guess you like

Origin blog.csdn.net/G971005287W/article/details/131922460