Created
December 10, 2018 20:16
-
-
Save jasonrundell/fe493f6ac069c5dd3535fa9ff5ac7af9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$datestamp = date("Y-m-d"); // used with file naming | |
$domain = "domain.com"; // change to the domain name of your client | |
$email = "[email protected]"; // change to your contact email | |
$db_host = "YOUR_DB_HOST"; | |
$db_user = "YOUR_DB_USERNAME"; | |
$db_pass = "YOUR_DB_PASSWORD"; | |
$db_name = "YOUR_DB_NAME"; | |
$csv_file_path = "$domain-$datestamp.csv"; | |
$s3_bucket = "your_s3_bucket_name"; // the name of your root backup folder on S3 | |
define("APP_AWS_ACCESS_KEY","YOUR_AWS_ACCESS_KEY"); | |
define("APP_AWS_SECRET_KEY","YOUR_AWS_SECRET_KEY"); | |
// core libraries | |
include_once "amazon-sdk/sdk.class.php"; | |
/** | |
* STUB: Run script to dump sql into CSV | |
*/ | |
/** END STUB */ | |
/** | |
* S3 Upload Start | |
*/ | |
if (is_writable($csv_file_path)) { | |
$result .= "$csv_file_path was found.\r\n"; | |
} else { | |
$result .= "$csv_file_path could not be found. Backup must have failed.\r\n"; | |
} | |
$s3 = new AmazonS3(); | |
// Upload an object. | |
if (is_writable($csv_file_path)) { | |
$result .= "$csv_file_path was found.\r\n"; | |
} else { | |
$result .= "$csv_file_path could not be found. Backup failed.\r\n"; | |
} | |
$response = $s3->create_object($s3_bucket, $csv_file_path, array( | |
'fileUpload' => $csv_file_path, | |
'metadataDirective' => 'REPLACE', | |
'storage' => AmazonS3::STORAGE_REDUCED, | |
'acl' => AmazonS3::ACL_PRIVATE | |
)); | |
ob_start(); | |
var_dump($response->isOK()); | |
$result .= "Result of S3 upload: ".ob_get_clean(). "(true = success, false = fail)\r\n\r\n"; | |
/** | |
* S3 Upload End | |
*/ | |
/** | |
* Clean up files | |
*/ | |
// cleanup | |
$command = "rm $csv_file_path"; // remove sql file | |
$result = exec($command,$output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment