大网数据广告活动
服务器运维问答

rsync: mkdir "2014-11/." failed: No such file or directory (2)

· 52CE 我爱测

i'm write a script for automation copying file with rsync from server-a to server-b this is my script : #!/bin/bash NOW=$(date +"%Y-%m") rsync -au --ignore-existing /var/www/uploads/$NOW/* -e [email omitted]:/var/www/uploads/$NOW…

问题原文

原帖链接 · syntaxerro · CC BY-SA 3.0

i'm write a script for automation copying file with rsync from server-a to server-b this is my script :

#!/bin/bash
NOW=$(date +"%Y-%m")
rsync -au --ignore-existing /var/www/uploads/$NOW/* -e [email omitted]:/var/www/uploads/$NOW/.

when we are going to an next month like from October to November , i get this error on my script :

`

rsync: mkdir "/var/www/uploads/2014-11/." failed: No such file or directory (2)
rsync error: error in file IO (code 11) at main.c(605) [Receiver=3.0.9]
rsync: connection unexpectedly closed (9 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(605) [sender=3.0.9]

` how should i fix this error ? please help me

社区高分解答

原帖链接 · mc0e · CC BY-SA 3.0

Firstly, make sure that the parent directory on the target exists. I.e. [email omitted]:/var/www/uploads should exist. I think with your formulation, the trailing . refers to a directory which rsync tries to create, and it can't do so unless the parent directory already exists. ie the parent is [email omitted]:/var/www/uploads/$NOW.

Secondly, realise that the behaviour of rsync is subtly different to cp in various ways with the trailing '/' on the file name. I find the safest and most intuitive way to do things is to use a trailing / on the end of all directories. Like so:

rsync -au --ignore-existing /var/www/uploads/$NOW/ -e [email omitted]:/var/www/uploads/$NOW/

Unlike cp, rsync will reliably copy the content of the directory in the source argument to the content of the target directory, creating the target directory if necessary (though it's parent must exist), and not putting the source directory (ie the parent) inside the target directory if the target already exists.

This is slightly different to what you were doing though in that the way you did it would exclude files with a name starting with . in the source directory, and would fail if the list of files being copied was too long (bash expansion capped at a total command line length of around 32K characters if memory serves me right).

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2014-11-02)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。