Created
January 6, 2015 06:55
-
-
Save danpette/3913646248b49ce8a03f to your computer and use it in GitHub Desktop.
MySQL Dump TO AWS Glacier
This file contains hidden or 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 | |
error_reporting(E_ALL); | |
ini_set('display_errors', 1); | |
define('SITE_ROOT', realpath(dirname(__FILE__))); | |
define('APP_PATH', dirname(__DIR__)); | |
session_cache_limiter(false); | |
session_start(); | |
require APP_PATH . '/vendor/autoload.php'; | |
use Aws\Glacier\GlacierClient; | |
use Aws\Common\Enum\Region; | |
$timestamp = date('Y-m-d H:i:s'); | |
$aws = GlacierClient::factory(array( | |
'key' => 'AAAAAAAAAAAAAAAAAAAA', //Your key and secret key are found at https://portal.aws.amazon.com/gp/aws/securityCredentials | |
'secret' => 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', | |
'region' => Region::EU_WEST_1 //This is the server cluster we are connecting to. US_EAST_1 is Northern Virginia. US_WEST_1 is Northern California. US_WEST_2 is Oregon | |
)); | |
use Ifsnop\Mysqldump as IMysqldump; | |
try { | |
$dump = new IMysqldump\Mysqldump('test', 'test', 'abcd1234','localhost'); | |
$dump->start('backup_'.$timestamp.'.sql'); | |
} catch (\Exception $e) { | |
echo 'mysqldump-php error: ' . $e->getMessage(); | |
} | |
$result = $aws->uploadArchive(array( | |
'vaultName' => 'ninjalink_backup', //Vault to add to | |
'archiveDescription' => 'SQL Backupfile ' . date('Y-m-d H:i:s'), //Description given to my file | |
'body' => fopen(APP_PATH . "/html/backup_".$timestamp.".sql", "r") //File itself being transferred | |
)); | |
$archiveId = $result->get('archiveId'); //Return the ID of the file I just uploaded. This is important, make sure to save it (along with other identifying info related to the file)! | |
echo $archiveId; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment