{"id":473,"date":"2016-03-01T12:16:24","date_gmt":"2016-03-01T12:16:24","guid":{"rendered":"http:\/\/www.haxed.me.uk\/?p=473"},"modified":"2016-03-01T14:58:44","modified_gmt":"2016-03-01T14:58:44","slug":"download-rackspace-cloud-files-containers-all-of-them-for-archiving","status":"publish","type":"post","link":"https:\/\/haxed.me.uk\/index.php\/2016\/03\/01\/download-rackspace-cloud-files-containers-all-of-them-for-archiving\/","title":{"rendered":"Download Rackspace Cloud Files Containers (all of them) for archiving"},"content":{"rendered":"<pre>\r\ncurl -sS https:\/\/getcomposer.org\/installer | php\r\nphp composer.phar require rackspace\/php-opencloud\r\n\r\n<\/pre>\n<p><code><\/p>\n<pre>\r\n< ? php\r\n\/**\r\n *  \"require\": {\r\n *      \"rackspace\/php-opencloud\": \"dev-master\"\r\n *  }\r\n *\/\r\n\r\nini_set('memory_limit', '2048M'); \/\/ size must be bigger than the biggest file\r\nini_set('max_execution_time', 0);\r\n\r\nrequire 'vendor\/autoload.php';\r\n\r\nuse OpenCloud\\Rackspace;\r\n\r\n\/\/ Instantiate a Rackspace client.\r\n$client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array(\r\n    'username' => 'mycloudusernamehere',\r\n    'apiKey'   => 'myapikeyhere'\r\n));\r\n\r\n$objStore = $client->objectStoreService('cloudFiles', 'LON');\r\n$savePath = __DIR__.'\/archive\/files\/';\r\n\r\n\/\/ get our containers\r\nprint(\"Containers:\\n\");\r\n$containersList = $objStore->listContainers();\r\n\r\nwhile($container = $containersList->Next()) {\r\n    if( ! in_array($container->name, array('.CDN_ACCESS_LOGS', '<CONTAINER_TO_EXCLUDE>'))) {\r\n        printf(\"*** %s\\n\", $container->name);\r\n\r\n        $containerDir = $savePath.$container->name.'\/';\r\n        if (!is_dir($containerDir)) {\r\n            mkdir($containerDir, 0777, true);\r\n        }\r\n\r\n        $files = $container->ObjectList();\r\n        while($o = $files->Next()) {\r\n            $file_name = $o->getName();\r\n\r\n            if (file_exists($containerDir . $file_name)) {\r\n                echo '## '.$containerDir.$file_name.' already exists'.\"\\n\";\r\n                continue;\r\n            }\r\n\r\n            \/\/ Get our object\r\n            $file = $container->getObject($file_name);\r\n\r\n            if (strpos($file->getName(), '<FILES_TO_EXCLUDE>') !== false) {\r\n                continue;\r\n            }\r\n\r\n            $tempDir = $containerDir . dirname($file->getName()) . '\/';\r\n            if (!is_dir($tempDir)) {\r\n                mkdir($tempDir, 0777, true);\r\n            }\r\n\r\n            if (file_put_contents($containerDir . $file_name, $file->getContent())) {\r\n                printf(\"** %s - OK\\n\", $file->getName());\r\n            } else {\r\n                printf(\"** %s - KO\\n\", $file->getName());\r\n            }\r\n            unset($file);\r\n        }\r\n    }\r\n}\r\n\r\n<\/pre>\n<p><\/code><\/p>\n<p>The script can be executed like <\/p>\n<pre>\r\nphp script.php \r\n\r\n<\/pre>\n<pre>\r\nphp cloud-files-php-downloader2.php\r\nContainers:\r\n*** meine.org.cdn.container\r\n** wp-content\/themes\/twentyfifteen\/css\/editor-style.css - OK\r\n** wp-content\/themes\/twentyfifteen\/css\/ie.css - OK\r\n** wp-content\/themes\/twentyfifteen\/css\/ie7.css - OK\r\n** wp-content\/themes\/twentyfifteen\/genericons\/Genericons.ttf - OK\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>curl -sS https:\/\/getcomposer.org\/installer | php php composer.phar require rackspace\/php-opencloud < ? php \/** * \"require\": { * \"rackspace\/php-opencloud\": \"dev-master\" * } *\/ ini_set('memory_limit', '2048M'); \/\/ size must be bigger than the biggest file ini_set('max_execution_time', 0); require 'vendor\/autoload.php'; use OpenCloud\\Rackspace; \/\/ &hellip; <a href=\"https:\/\/haxed.me.uk\/index.php\/2016\/03\/01\/download-rackspace-cloud-files-containers-all-of-them-for-archiving\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"class_list":["post-473","post","type-post","status-publish","format-standard","hentry","category-cloud-files"],"_links":{"self":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/comments?post=473"}],"version-history":[{"count":6,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/473\/revisions"}],"predecessor-version":[{"id":481,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/473\/revisions\/481"}],"wp:attachment":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/media?parent=473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/categories?post=473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/tags?post=473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}