Skip to content

Instantly share code, notes, and snippets.

@steveh
Created October 7, 2009 00:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveh/203614 to your computer and use it in GitHub Desktop.
Save steveh/203614 to your computer and use it in GitHub Desktop.
<?php
$start_time = microtime (true);
function timer () {
global $start_time;
return sprintf ('%05.1f ', microtime(true)-$start_time);
}
$parent_dir = realpath (dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);
set_include_path (get_include_path() . PATH_SEPARATOR . $parent_dir);
chdir ($parent_dir);
require 'config.php';
// Set up s3sync variables
putenv ("AWS_ACCESS_KEY_ID={$_CONFIG['s3']['access_key_id']}");
putenv ("AWS_SECRET_ACCESS_KEY={$_CONFIG['s3']['secret_access_key']}");
print timer()."Begin\n";
// MySQL dump
$dump_bucket = "safetybase-mysql-".date('Y');
$dump_filename = "mysqldump-{$_CONFIG['database']['database']}-".date('YmdHis').".bz2";
$dump_path = "/tmp/$dump_filename";
passthru ("./cron/s3sync/s3cmd.rb createbucket $dump_bucket");
print timer()."Created bucket $dump_bucket\n";
passthru ("mysqldump -u{$_CONFIG['database']['username']} -p{$_CONFIG['database']['password']} --opt {$_CONFIG['database']['database']} | bzip2 > $dump_path");
print timer()."Dumped {$_CONFIG['database']['database']} to $dump_path\n";
passthru ("./cron/s3sync/s3cmd.rb put $dump_bucket:$dump_filename $dump_path");
print timer()."Uploaded {$_CONFIG['database']['database']} to $dump_bucket\n";
// Files
$files_bucket = "safetybase-files";
passthru ("./cron/s3sync/s3cmd.rb createbucket $files_bucket");
print timer()."Created bucket $files_bucket\n";
passthru ("./cron/s3sync/s3sync.rb -r -v {$_CONFIG['dir']['files']} $files_bucket:");
print timer()."Synced {$_CONFIG['dir']['files']} to $files_bucket\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment