在容器机架空间 CDN 中过滤文件


filtering files in container rackspace cdn

我正在尝试为云文件编写备份脚本(使用Rackspace),该脚本只会复制自上次备份时间以来修改的文件。

有没有办法查询自特定时间以来修改的列表文件?(使用 PHP )

注意:使用 php-opencloud 库。

目前,我还没有找到根据上次修改日期进行查询/过滤的方法。

您可以做的是查看容器中每个对象的元数据。在低级别,这只需要对每个对象执行 HEAD 操作。虽然这可能要求您检查每个对象,但您只是抓取标头而不是下载每个标头。

上次修改日期是在对对象进行 HEAD 操作时的 HTTP 标头中:

HEAD /<api version>/<account>/<container>/<object> HTTP/1.1
Host: storage.clouddrive.com
X-Auth-Token: eaaafd18-0fed-4b3a-81b4-663c99ec1cbb

不返回响应正文,但 HTTP 标头具有多汁的详细信息:

HTTP/1.1 200 OK
Date: Thu, 07 Jun 2007 20:59:39 GMT
Last-Modified: Fri, 12 Jun 2007 13:40:18 GMT
ETag: 8a964ee2a5e88be344f36c22562a6486
Content-Length: 512000
Content-Type: text/plain; charset=UTF-8
X-Object-Meta-Meat: Bacon

PHP 库中有一个名为 fetch 的方法,可以只获取对象的标头,但它是私有的,我没有看到它在任何地方使用。这看起来像是在 GitHub 上提出问题或为自己制作 PR 的类型。

现在,您可以获取每个对象并自己提取标题:

$obj = $container->DataObject();
$headers = $obj->metadataHeaders();
$headers["Last-Modified"]

对不起,这并没有完全帮助。我直接 ping 了一位 PHP 开发人员,如果这不起作用,希望我们会找到另一种选择。

尝试使用 glob() 和 filemtime()。

例:

$lastBackupTime = 1234567890; //You'll have to figure out how to store and retrieve this
$modified = array();
// Change the input of glob() to use the directory and file extension you're looking for
foreach (glob('/some/directory/*.txt') as $file) {
    if (filemtime($file) > $lastBackupTime) {
        $modified[] = $file;
    }
}
foreach ($modified as $file) {
    //do something
}