从未挂载的 webdav 源进行 rsync

从未挂载的 webdav 源进行 rsync

我有一个白色标签、无品牌的闭路电视摄像机通过 webdav 服务器公开所有记录。过去一个月左右,我一直在使用 安装驱动器davfs2,但这不是一个特别优雅的解决方案:

  • 必须为每个(cptar)命令重新生成文件列表,这需要一段时间
  • cp每次连续传输文件后似乎速度会稍微减慢
  • rsync --progress似乎只测量从临时文件到最终目的地的本地传输速度

我见过一些人用来rsync备份到各种类型的基于 webdav 的云服务器,但是当我尝试时:

rsync -a admin@http://192.168.0.22/webdav/ /media/martin/internal-large/CCTV-TWO/

我得到的只是错误:

ssh: Could not resolve hostname http: Name or service not known

有没有办法通过这种方式进行转移?

编辑评论:我怀疑我的问题措辞太差,无法理解。首先,webdav 是源。其次,如果您只使用 IP 地址,那么 rsync 会假定您想要基于 SSH 的传输。

如果我发出命令:rsync --progress -a [email protected]:/webdav /media/martin/internal-large/CCTV-TWO/

我收到以下错误:

ssh: connect to host 192.168.0.24 port 22: Connection refused 
rsync: connection unexpectedly closed (0 bytes received so far)
[Receiver] rsync error: unexplained error (code 255) at io.c(226)

答案1

作为 rsync 的替代方法,完成此任务的一种方法是使用wget-m(--mirror)开关,该开关应用 -r(递归)、-N(将时间戳与远程文件匹配)无限级别深度(您可能希望或不希望使用 -l 开关来缩减),并且还应用 --no-remove-listing 开关(FTP 传输选项,我认为通过 HTTP 传输时并不重要)

我们还需要明确指定存储目录,以避免将所有内容转储到启动 wget 的目录中(我记得这是默认行为)

我们可以使用 -P 开关执行此操作,如 -P目标或 --directory-prefix=target

您还可能希望避免使用适用的 -np(--no-parent)开关爬升到您所针对的源目录之上:

Do not ever ascend to the parent directory when retrieving recursively.
This is a useful option, since it guarantees that only the files below 
a certain hierarchy will be downloaded.

您可以按如下方式指定凭据:

--user=user
--password=password

 Specifies the username user and password password for both FTP and HTTP file retrieval.  These parameters can be overridden using the --ftp-user and
           --ftp-password options for FTP connections and the --http-user and --http-password options for HTTP connections.

将所有这些放在一起,我最终得到了如下命令。

wget -m 192.168.0.22/webdav/ -np -P ./media/martin/internal-large/CCTV-TWO/

根据您的情况,您可能需要或不需要添加 --user=admin 和 --password=whateveritis 开关。

可能还有其他有用的开关适合您的特定用例。该命令有一个详细的手册页,man wget您可能特别希望查看的是,--no-clobber我在下面附上了手册页的摘录:

--no-clobber
           If a file is downloaded more than once in the same directory,
           Wget's behavior depends on a few options, including -nc.  In
           certain cases, the local file will be clobbered, or overwritten,
           upon repeated download.  In other cases it will be preserved.

           When running Wget without -N, -nc, -r, or -p, downloading the same
           file in the same directory will result in the original copy of file
           being preserved and the second copy being named file.1.  If that
           file is downloaded yet again, the third copy will be named file.2,
--
           Therefore, ""no-clobber"" is actually a misnomer in this
           mode---it's not clobbering that's prevented (as the numeric
           suffixes were already preventing clobbering), but rather the
           multiple version saving that's prevented.

           When running Wget with -r or -p, but without -N, -nd, or -nc, re-
           downloading a file will result in the new copy simply overwriting
           the old.  Adding -nc will prevent this behavior, instead causing
           the original version to be preserved and any newer copies on the
           server to be ignored.

资料来源:

man wget

https://stackoverflow.com/questions/1078524/how-to-specify-the-location-with-wget

https://stackoverflow.com/questions/17282915/download-an-entire-directory-using-wget

相关内容