Backup Amazon S3 with PHP

19 Aug

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

/* url for Amazon Bucket */
$bucketurl = “;;
$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, $matches, PREG_PATTERN_ORDER);
return $matches[1];



Tags: , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: