[英]Rsync Copies Whole Directory Content Instead of Single File
我遇到了 rsync 命令的問題,該命令正在執行我不期望的額外工作。 下面的命令應該只將單個文件 rsync 到目標服務器的目錄。
但是,即使我嘗試從該目錄中--exclude
所有其他文件,它也會將${OUT_DIR}/make
目錄中的額外文件復制到目標中。
如何讓 rsync 只復制目標文件?
eval rsync -azu --delete \
--include ${OUT_DIR}/make/file.mk \
--exclude ${OUT_DIR}/make \
${OUT_DIR}/make/file.mk
${DEST_USER}@${DEST_SVR}:$OUT_DIR_DEST/make
我已經嘗試刪除“額外”選項,但是我在這樣做時遇到了錯誤,因此嘗試使上述命令正常工作似乎是最好的行動方案。 但是當我嘗試改變它時,這是我得到的:
eval rsync \
${OUT_DIR}/make/file.mk
${DEST_USER}@${DEST_SVR}:$OUT_DIR_DEST/make
Incompatible options specified for inc-recursive connection.
rsync error: syntax or usage error (code 1) at compat.c(268) [sender=3.0.6]
刪除 --delete 相關選項:
eval rsync -azu
${OUT_DIR}/make/file.mk
${DEST_USER}@${DEST_SVR}:$OUT_DIR_DEST/make
opening connection using: ssh -x -i ... rsync --server -vvulogDtprze.iLs .
$OUT_DIR_DEST/make
note: iconv_open("UTF-8", "UTF-8") succeeded.
(Client) Protocol versions: remote=30, negotiated=30
sending incremental file list
[sender] make_file(file.mk,*,0)
[sender] flist start=1, used=1, low=0, high=0
[sender] i=1 /OUTDIR/path file.mk mode=0100664 len=91 uid=300 gid=301 flags=5
send_file_list done
file list sent
send_files starting
ERROR: buffer overflow in recv_rules [receiver]
rsync error: error allocating core memory buffers (code 22) at util.c(123) [receiver=3.0.6]
rsync: connection unexpectedly closed (9 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(600) [sender=3.0.6]
_exit_cleanup(code=12, file=io.c, line=600): entered
_exit_cleanup(code=12, file=io.c, line=600): about to call exit(12)
我所做的大部分谷歌搜索都沒有為這兩個問題找到任何明顯的解決方案。
我將eval
業務,因為其中的任何額外擴展都不清楚,但我可以向您展示 rsync 應該是什么樣子。 如果您使用bash或zsh的,那么你可以不set -x
,它會告訴你它運行真正的樣子變擴建后什么命令。
最簡單的解決方案是這樣的:
rsync -azu \
/local/path/to/make/file.mk \
user@server:/remote/path/to/make/
如果你真的想使用包含/排除規則(如果有多個包含就好了,也許)那么這樣做:
rsync -azu \
--include=file.mk \
--exclude='*' \
/local/path/to/make/ \
user@server:/remote/path/to/make/
--include
模式相對於源目錄的根目錄,因此如果您說--include=/local/path/to/make/file.mk
那么該模式將只匹配名為/local/path/to/make/local/path/to/make/file.mk
,這顯然不是你的意思。
--exclude
規則的工作方式相同,所以基本上你告訴它排除不存在的東西,所以沒有排除任何東西。 --exclude='*'
表示排除所有內容(尚未明確包含的內容),因此您不會收到此類錯誤。
您可以使用--relative
選項更改這些規則。 我認為這可能會使您的原始命令起作用,但它會在遠程系統上創建文件: /remote/path/to/make/local/path/to/make/file.mk
不管你怎么做,包含規則都需要在排除規則之前:rsync 使用匹配任何給定文件或目錄的第一個規則。
您發布的錯誤消息表明遠程機器內存不足:
ERROR: buffer overflow in recv_rules [receiver]
rsync error: error allocating core memory buffers (code 22) at util.c(123) [receiver=3.0.6]
內存使用在 3.0 中得到了極大的改善,但是您似乎擁有 3.0.6,所以大概這不是您可以修復的。 嘗試新版本(我有 3.1.2)可能不是一個糟糕的計划。
如果該文件夾下有很多文件(除了一個之外的所有文件),那么您可以通過避免遞歸選項來節省內存:
rsync -ptgo -zu \
/local/path/to/make/file.mk \
user@server:/remote/path/to/make/
我所做的只是將-a
替換為等效的-rlptgoD
,然后刪除了不必要的選項,尤其是-r
。
如果所有其他方法都失敗了,您可以嘗試在該機器上添加交換文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.