Skip to content

Instantly share code, notes, and snippets.

@eporama
Last active August 29, 2015 14:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eporama/a8eb2f23e6982409108e to your computer and use it in GitHub Desktop.
Save eporama/a8eb2f23e6982409108e to your computer and use it in GitHub Desktop.
<?php
define("USER", "epor...");
define("PASSWORD", "jDey...");
define("SITE", "eporama");
define("ENV", "dev");
define("REALM", "devcloud"); // use devcloud for ACP and free tier, 'prod' for ACE
define("DB", "eporama");
define("LOCAL_PATH", "/Users/erik.peterson/backups/");
kickoff();
function kickoff() {
echo "getting backups...\n";
$my_backups = list_backups();
$latest = 0;
foreach ($my_backups as $backup) {
if ($backup->type == 'daily') {
if ($backup->completed > $latest) {
$latest = $backup->completed;
$final_id = $backup->id;
}
}
}
print "latest backup: $final_id" . "\n";
retrieve_backup($final_id);
}
function list_backups() {
// This function returns the list of backups available
$backups = getresults(SITE . '/envs/'. ENV . '/dbs/' . DB . '/backups', 'GET');
return $backups;
}
function retrieve_backup($backupid) {
//This function will retrieve a backup
echo "Retrieving backup information \n";
$backupinfo = getresults(SITE . '/envs/'. ENV . '/dbs/' . DB . '/backups/' . $backupid);
$link = $backupinfo->link;
download_file($link, $backupid);
}
function download_file($link, $backupid) {
// Attempt to wget file from a $link
echo "Retrieving backup file \n";
$local_path = LOCAL_PATH . SITE . '/' . ENV . '/';
if (!is_dir($local_path)) {
mkdir($local_path, 0770, TRUE);
}
$ch = curl_init($link);
$fp = fopen($local_path . "backup-". DB . "-" . $backupid . ".sql.gz", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
echo "Backup retrieved to $local_path\n";
}
function getresults($cmd, $method="GET") {
$cmd = "curl -s -u " . USER . ":" . PASSWORD . " -X $method https://cloudapi.acquia.com/v1/sites/" . REALM . ":$cmd.json";
$results = exec($cmd);
return json_decode($results);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment