在 PHP 中从目录构建 Tar 文件,无需 exec/passthru
所以我有一个客户,其当前主机不允许我通过 exec()/passthru()/ect 使用 tar,我需要定期以编程方式备份该站点,那么有解决方案吗?
这是一个Linux服务器。
So I have a client who's current host does not allow me to use tar via exec()/passthru()/ect and I need to backup the site periodicly and programmaticly so is there a solution?
This is a linux server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
PHP 5.3 提供了一种更简单的方法来解决这个问题。
请看这里:http://www.php.net/manual/en/phardata。从目录构建.php
PHP 5.3 offers a much easier way to solve this issue.
Look here: http://www.php.net/manual/en/phardata.buildfromdirectory.php
在 http://pear.php.net/package/Archive_Tar 您可以下载 PEAR tar 包并像这样使用它来创建存档:
At http://pear.php.net/package/Archive_Tar you can donload the PEAR tar package and use it like this to create the archive:
有 Archive_Tar 库。 如果由于某种原因无法使用,zip 扩展可能是另一个选择。
There is the Archive_Tar library. If that can't be used for some reason, the zip extension might be another option.
我需要一个可以在 Azure 网站(IIS)上运行的解决方案,并且在使用其他答案中的方法在服务器上创建新文件时遇到问题。 对我有用的解决方案是使用小型 TbsZip 库压缩,不需要将文件写入服务器中的任何位置 - 它只是通过 HTTP 直接返回。
这个线程很旧,但这种方法可能是更通用和完整的答案,所以我将代码作为替代方法发布:
这是整个 我的博客上的文章。
I need a solution that would work on Azure websites (IIS) and had trouble with creating new files on the server using methods from other answers. The solution that worked for me was to use small TbsZip library for compression, which doesn't require to write file anywhere in the server - it's just returned directly via HTTP.
This thread is old, but this approach might be a bit more generic and complete answer, so I post the code as alternative:
And here's the whole article on my blog.