Created
October 26, 2015 06:29
-
-
Save danpette/91c6c1e6136003d07081 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 | |
$Log->addInfo('backup_daily_start'); | |
use Aws\Glacier\GlacierClient; | |
use Aws\Common\Enum\Region; | |
use Aws\S3\S3Client; | |
use Ifsnop\Mysqldump as IMysqldump; | |
try { | |
$timestamp = date('Y-m-d H:i:s'); | |
try { | |
$dump = new IMysqldump\Mysqldump('database', 'username', 'password', 'localhost','mysql',[],[ | |
PDO::ATTR_PERSISTENT => true, | |
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, | |
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false, | |
PDO::MYSQL_ATTR_SSL_CA => '/some/dir/to/if/needs/rds-combined-ca-bundle.pem' | |
]); | |
$dump->start(APP_PATH . '/cron/backup/backup_' . $timestamp . '.sql'); | |
} catch (\Exception $e) { | |
$Log->addInfo('backup_daily_phpdump_error', ['error' => $e->getMessage()]); | |
} | |
$s3 = S3Client::factory(array( | |
'key' => 'key', | |
'secret' => 'secret', | |
'region' => 'eu-west-1' | |
)); | |
try { | |
// Upload data. | |
$result = $s3->putObject(array( | |
'Bucket' => 'somebackupbucket', | |
'Key' => 'sqlbackup_' . $timestamp, | |
'SourceFile' => APP_PATH . "/cron/backup/backup_" . $timestamp . ".sql", | |
'ACL' => 'private', | |
'ContentType' => 'application/octet-stream', | |
'ServerSideEncryption' => 'AES256' | |
)); | |
} catch (S3Exception $e) { | |
$Log->addInfo('backup_s3_failed', [[$e->getMessage(), $e->getFile(), $e->getCode(), $e->getLine()]]); | |
} | |
try { | |
unlink(APP_PATH . "/cron/backup/backup_" . $timestamp . ".sql"); | |
} catch (Mandrill_Error $e) { | |
//$Log->addInfo('backup_daily_failed_email', ['timestamp' => date('YmdHis'), 'error' => $e]); | |
} | |
$Log->addInfo('backup_daily_success'); | |
} catch (Exception $e) { | |
$Log->addInfo('backup_daily_failed', [[$e->getMessage(), $e->getFile(), $e->getCode(), $e->getLine()]]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment