rsync同步省略目录
好吧,我可能不是第一个尝试将基于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于不需要创建或删除该目录,因此 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.