Backup Amazon S3 with PHP


Hits: 2247  

This is the source code to backup/download Amazon S3 Bucket’s multimedia files to other server by PHP…

here $bucketurl is XML url of Amazon S3 bucket with full ACL.
$folder is path of the server where S3 files to store.

This script will download all files in Amazon bucket to other server

Php-Code:
 1 
 2 
 3 
 4 
 5 
 6 
 7 
 8 
 9 
 10 
 11 
 12 
 13 
 14 
 15 
 16 
 17 
 18 
 19 
 20 
 21 
 22 
 23 
 24 

<?php

/* url for Amazon Bucket */

$bucketurl "http://BUCKETNAME.s3.amazonaws.com/";

$xml file_get_contents($bucketurl);

/* folder name for server */

$folder "/var/www/html/BUCKETNAME/";

$content getTag'Key'$xml );

foreach($content as $file)

{

exec"wget -O ".$folder.$file." ".$bucketurl.$file );

}

/* function to get node from Amazon Bucket XML */

function getTag$tag$xml )

{

$tag preg_quote($tag);

preg_match_all('{<'.$tag.'[^>]*>(.*?)</'.$tag.'>}'$xml$matchesPREG_PATTERN_ORDER);

return 
$matches[1];

}

?>

Published by

Sandeep Verma

I’m an Entrepreneur. I’m proud to work as Blogger, LAMP Programmer, Linux Admin, Web Consultant, Cloud Manager, Apps Developer, Searcher. Concentrate > Observe > Imagine > Launch