Linux:仅rsync复制目录结构树

时间:2020-01-09 10:45:59  来源:igfitidea点击:

如何复制目录结构树而不在Linux或者UNIX操作系统下复制任何文件以删除服务器或者本地目录?
您需要使用rsync命令。

rsync远程更新协议允许rsync仅传输

使用有效的校验和搜索算法,可以确定整个网络连接上两组文件之间的差异。
确保将其安装在所有服务器上以进行远程复制。
仅复制目录树的语法如下:

rsync -av -f"+ */" -f"- *" /path/to/src /path/to/dest/
rsync -av -f"+ */" -f"- *" /path/to/apache/logs/ [email protected]:/path/to/apache/logs/

如果您使用的是较旧的rsync版本,请尝试:

rsync -av --include='*/' --exclude='*' /path/to/src /path/to/dest/
rsync -av --include='*/' --exclude='*' /path/to/apache/logs/ [email protected]:/path/to/apache/logs/

rsync命令仅用于目录结构/仅用于树

对于每个域,请在/var/logs/apache /中考虑以下布局:

cricketnow.in/
theitroad.local/
hexindia.net/
io9.in/
theitroad.com/
theitroad.com/

您可以通过排除其他所有内容来仅同步目录。
打开命令行终端(选择应用程序>附件>终端),然后执行以下命令或者使用ssh登录到远程服务器。
您要复制所有目录,即排除目录以外的所有目录,请执行:

# cd /var/log/apache/
# rsync -av -f"+ */" -f"- *" . [email protected]:/var/log/apache/

输出示例:

building file list ... done
./
cricketnow.in/
theitroad.local/
hexindia.net/
io9.in/
theitroad.com/
theitroad.com/

sent 388 bytes  received 98 bytes  972.00 bytes/sec
total size is 0  speedup is 0.00

您还可以按以下方式制作本地副本:

# cd /var/log/apache/
# rsync -av -f"+ */" -f"- *" . /jailfs/apache/httpd_root/var/log/apache/