我有 2 个系统
1: 192.168.0.31
2: 192.168.0.32
从系统 1 终端我执行以下命令
tar -zcf - test | pv | nc -l -p 5555 -q 5
从系统 2 终端我执行以下命令
nc 192.168.0.31 5555 | pv | tar -zxf -
现在,完整的测试文件夹及其包含的所有文件都复制到系统 2
我怎样才能使用crontab
或其他方法来安排这两个命令?
答案1
看来您想将一台计算机中的数据备份/复制到另一台计算机中。
一个非常简单且安全的解决方案可能是使用scp
基于的ssh
。
scp
示例命令可能如下所示:
scp -r /path/to/local/folder user@remotehost:/path/to/remote/folder
例如
假如说:
- 您的用户名是
shaji
- 您想从
192.168.0.31
/home/shaji
- 进入
192.168.0.32
文件夹/backup/shaji/backup
- 您的用户名是
您应该运行以下命令
192.168.0.31
:scp -r /home/shaji [email protected]:/home/shaji/backup
注意:您可以使用scp command
运行crontab
scp — 安全复制(远程文件复制程序)
描述
scp copies files between hosts on a network. It uses ssh(1) for data transfer, and uses the same authentication and provides the same security as ssh(1). Unlike rcp(1), scp will ask for passwords or passphrases if they are needed for authentication. File names may contain a user and host specification to indicate that the file is to be copied to/from that host. Local file names can be made explicit using absolute or relative pathnames to avoid scp treating file names containing ‘:’ as host specifiers. Copies between two remote hosts are also permitted. -r Recursively copy entire directories. Note that scp follows symbolic links encountered in the tree traversal.
有一些先决条件:
sshd
应该在远程主机上运行- 设置无密码 ssh 访问远程主机 -参见 askubuntu 问答