-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
29 lines (24 loc) · 861 Bytes
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
/**
* Author: Pandurang Zambare, [email protected]
*
* Script to Take DB backup locally and the Upload to S3.
**/
$dbname = 'database';
$dbhost = 'hostname';
$dbuser = 'username';
$dbpass = 'password';
$aws['awsAccessKey'] = "Your AWS key";
$aws['awsSecretKey'] = "Your AWS secret key";
$aws['awsBucketName'] = "Your AWS Bucket Name";
$backupFile = "/tmp/".$dbname . date("j-M-Y") . '.gz';
$command = "mysqldump --opt -h $dbhost -u$dbuser -p$dbpass $dbname | gzip > $backupFile";
system($command);
include(APPPATH.'s3.php');
$s3obj = new S3($aws['awsAccessKey'], $aws['awsSecretKey'])
$put = $s3obj->putObjectFile($backupFile, $aws['awsBucketName'], "db_backup/".date("Y",time())."/".baseName($backupFile), S3::ACL_PRIVATE);
if($put) {
echo "Successfully uploaded Backup.";
}
@unlink($backupFile);
?>