简体   繁体   English

过滤容器机架CDN中的文件

[英]filtering files in container rackspace cdn

I am trying to write a backup script for cloudfiles (using Rackspace) , which will only copy the files that are modified since the last backup time. 我正在尝试为cloudfiles(使用Rackspace)编写备份脚本,该脚本仅复制自上次备份以来修改的文件。

Is there a way to query for a list files that are modified since a specific time ? 有没有一种方法可以查询自特定时间以来已修改的列表文件? (Using PHP ) (使用PHP)

Note: using php-opencloud library. 注意:使用php-opencloud库。

Currently, I haven't found a way to query/filter based on the last modified date. 目前,我还没有找到一种基于上次修改日期进行查询/过滤的方法。

What you can do is look at the metadata for each object in a container. 您可以做的是查看容器中每个对象的元数据。 At a low level, this requires just a HEAD operation on each object. 在低级别上,这仅需要对每个对象执行HEAD操作。 While this probably requires you to check each object, you're only grabbing the headers and not downloading each one. 尽管这可能需要您检查每个对象,但您只是抓住标题而没有下载每个对象。

The last modified date is in the HTTP headers when making a HEAD operation on an object: 对对象执行HEAD操作时, 最后修改日期在HTTP标头中

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

No response body is returned, but the HTTP headers have juicy details: 没有返回响应主体,但是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

There is a method in the PHP library called fetch that can get just the headers of the object, but it's private and I don't see it being used anywhere . PHP库中有一个名为fetch的方法,该方法只能获取对象的标头 ,但它是私有的,我看不到它在任何地方都在使用。 This looks like the type of thing to raise an issue on GitHub or make a PR of your own for. 这看起来像是在GitHub上引发问题或自行创建PR的事情。

Right now you can get each object and pull the headers out yourself: 现在,您可以获取每个对象并自己拉出标题:

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

Sorry that doesn't help completely. 抱歉,这无法完全解决问题。 I pinged one of the PHP devs directly and hopefully we'll find another option if this doesn't work out. 我直接对其中一个PHP开发人员执行了ping操作,希望如果这种方法无法解决,我们将找到另一个选择。

Try using glob() and filemtime() . 尝试使用glob()filemtime()

Example: 例:

$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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM