rsync同步省略目录

发布于 2024-08-12 08:25:06 字数 1584 浏览 6 评论 0原文

好吧,我可能不是第一个尝试将基于 PHP Web 的 rsync 界面组合在一起以简化部署的人,但事实就是如此。

我们在本地有一个“QA”服务器,在 Rackspace 上有一个“临时”服务器。我已经设置了 SSH 密钥配对,这样我就可以在两台服务器之间进行 rsync,一切都很好。问题是 rsync 在决定需要更新的内容方面有点不稳定。

我编写的脚本首先使用“--dry-run”参数执行 rsync,以获取需要传输的所有内容的列表。命令如下:

$strCheck = shell_exec(
                       "rsync " .
                       "--verbose " .
                       "--recursive " .
                       "--safe-links " .
                       "--checksum " .
                       "--dry-run " .
                       "--delete " .
                       "--delete-excluded " .
                       "--force " .
                       "--cvs-exclude " .
                       "--human-readable " .
                       "/apps/{$system}/ " .
                       "user@liveserver:/apps/{$system}_staging/"
                       );

现在一切正常,我可以将返回的字符串解析为需要删除的内容和需要添加/更新的内容。然后,我构建一个 HTML 表,该表根据每个复选框在层次结构中的位置自动缩进。我还使用了一些 JavaScript,这样我就可以允许用户选择文件夹中的所有文件。

如果要添加/删除文件夹本身,则会将其包含在列表中。例如:

/newfolder/
/newfolder/file1.php
/newfolder/file2.php

这很好,因为“/newfolder/”将以一个缩进显示,而“/newfolder/file1.php”和“/newfolder/file2.php”将在“/newfolder/”下方显示两个缩进。 “/newfolder/”旁边的复选框将自动选择两个“子”文件,每个人都很高兴。

但是,如果只是向文件夹添加/更新文件,则会忽略文件夹本身:

/oldfolder/filea.php
/oldfolder/fileb.php

...

这意味着“/oldfolder/”中的所有文件将有两个缩进,但没有可见的机制可以选择所有文件文件夹中的文件。

所以我的问题是:可用的 rsync 参数中是否缺少某些内容,我可以强制它包含任何更新文件的文件夹,或者我是否必须在循环数组时添加它们?如果是后者,最好的方法是什么?

帮助我 Obi Stack Overflowbi,你是我唯一的希望......

OK, I'm probably not the first person to attempt to put together a PHP web-based interface to rsync to ease deployment, but there goes.

We have a 'QA' server locally and a 'Staging' server at Rackspace. I've set up SSH key pairings so I can rsync between the two servers and it all works great. The problem is that rsync is a bit flaky as to what it decides needs updating.

The script I have written first executes rsync with the '--dry-run' parameter to get a list of everything that needs transferring. The command is as follows:

$strCheck = shell_exec(
                       "rsync " .
                       "--verbose " .
                       "--recursive " .
                       "--safe-links " .
                       "--checksum " .
                       "--dry-run " .
                       "--delete " .
                       "--delete-excluded " .
                       "--force " .
                       "--cvs-exclude " .
                       "--human-readable " .
                       "/apps/{$system}/ " .
                       "user@liveserver:/apps/{$system}_staging/"
                       );

Now this all works fine and I can parse the string that's returned into stuff that needs deleting and stuff that needs adding/updating. I then construct a HTML table that automatically indents each checkbox based on where it is in the hierarchy. I also use a bit of javascript so I can allow the user to select all files in a folder.

If a folder itself is to be added/deleted, it includes it in the list. For example:

/newfolder/
/newfolder/file1.php
/newfolder/file2.php

which is great, because '/newfolder/' will be displayed with one indent and '/newfolder/file1.php' and '/newfolder/file2.php' will each be displayed with two indents underneath '/newfolder/'. The checkbox next to '/newfolder/' will automatically select the two 'child' files and everyone is happy.

However, if it is just adding/updating files to a folder, it omits the folder itself:

/oldfolder/filea.php
/oldfolder/fileb.php

...

Which means all the files in '/oldfolder/' will have two indents, but there is no visible mechanism with which to select all the files in the folder.

So my question is this: is there something I am missing in the available rsync parameters where I can force it to include the folder for any updated files, or am I going to have to add them in as I loop through the array? If it's the latter, what would be the best way of doing that?

Help me Obi Stack Overflowbi, you're my only hope...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

山川志 2024-08-19 08:25:06

由于不需要创建或删除该目录,因此 rsync 返回的列表中将缺少该目录。我不相信有任何方法可以解决这个问题。

我认为你最好的选择是获得类似这样的路径


$路径 = 爆炸(PATH_SEPARATOR, 目录名($文件名) );

其中 $filename 是您的文件名。

Since the directory does not need to be created or deleted it will be missing from the list rsync returns. I don't believe there is any way to fix that.

I think your best bet would be to get the paths something like this


$path = explode(PATH_SEPARATOR, dirname($filename) );

Where $filename is your files name.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文