سؤال

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.

Is there a way to query for a list files that are modified since a specific time ? (Using PHP )

Note: using php-opencloud library.

هل كانت مفيدة؟

المحلول

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. 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 /<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/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. This looks like the type of thing to raise an issue on GitHub or make a PR of your own for.

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.

نصائح أخرى

Try using glob() and 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 مع الإسناد
لا تنتمي إلى StackOverflow
scroll top