Skip to content
Permalink
Browse files

IN-6160 - apply patch for adding s3 support to the backup module

  • Loading branch information...
GameGamer43 committed Feb 17, 2015
1 parent a030032 commit 84b41601ad66c244e9d9bed2228fbe85b62aebf0
@@ -9,7 +9,7 @@
require_once($dir . '/functions.inc/servers.php');
require_once($dir . '/functions.inc/templates.php');
require_once($dir . '/functions.inc/restore.php');
require_once($dir . '/functions.inc/s3.php');
/**
* do variable substitution
@@ -370,6 +370,29 @@ function store_backup() {
$this->b['error'] = _("Error connecting to the FTP Server...");
backup_log($this->b['error']);
}
break;
case 'awss3':
//dont run if the file is too over 2GB
if (filesize($this->b['_tmpfile']) > 2147483648) {
continue;
}
//subsitute variables if nesesary
$s['bucket'] = backup__($s['bucket']);
$s['awsaccesskey'] = backup__($s['awsaccesskey']);
$s['awssecret'] = backup__($s['awssecret']);
$awss3 = new S3($s['awsaccesskey'], $s['awssecret']);
$awss3->putBucket($s['bucket'], S3::ACL_PUBLIC_READ);
//copy file
if ($awss3->putObjectFile($this->b['_tmpfile'], $s['bucket'], $this->b['_file'] . '.tgz', S3::ACL_PUBLIC_READ)) {
dbug('S3 successfully uploaded your backup file.');
} else {
dbug('S3 failed to accept your backup file');
}
//run maintenance on the directory
$this->maintenance($s['type'], $s, $awss3);
break;
case 'ssh':
//subsitute variables if nesesary
@@ -540,6 +563,12 @@ private function maintenance($type, $data, $handle = '') {
exec(implode(' ', $cmd), $dir);
unset($cmd);
break;
case 'awss3':
$contents = $handle->getBucket($data['bucket']);
foreach ($contents as $file) {
$dir[] = $file['name'];
}
break;
}
//sanitize file list
@@ -588,6 +617,9 @@ private function maintenance($type, $data, $handle = '') {
ftp_delete($handle, $file);
unset($delete[$key]);
break;
case 'awss3':
$handle->deleteObject($data['bucket'],baseName($file));
break;
case 'ssh':
$cmd[] = fpbx_which('ssh');
$cmd[] = '-o StrictHostKeyChecking=no -i';
@@ -134,6 +134,26 @@ function backup_jstree_list_dir($id, $path = '') {
}
}
break;
case 'awss3':
$s['bucket'] = backup__($s['bucket']);
$s['awsaccesskey'] = backup__($s['awsaccesskey']);
$s['awssecret'] = backup__($s['awssecret']);
$awss3 = new S3($s['awsaccesskey'], $s['awssecret']);
$contents = $awss3->getBucket($s['bucket']);
foreach ($contents as $f){
if (substr($f['name'], -7) == '.tar.gz' || substr($f['name'], -4) == '.tgz') {
$ret[] = array(
'attr' => array(
'data-manifest' => json_encode(backup_get_manifest_db($f['name'])),
'data-path' => $path . '/' . $f['name']
),
'data' => $f['name']
);
}
}
break;
}
return $ret;
@@ -304,6 +324,19 @@ function backup_restore_locate_file($id, $path) {
return array('error_msg' => _('Failed to retrieve file from server!'));
}
break;
case 'awss3':
$s['bucket'] = backup__($s['bucket']);
$s['awsaccesskey'] = backup__($s['awsaccesskey']);
$s['awssecret'] = backup__($s['awssecret']);
$awss3 = new S3($s['awsaccesskey'], $s['awssecret']);
dbug('S3 Path: ' . $path);
dbug('S3 Dest: ' . $dest);
if ($awss3->getObject($s['bucket'],$path,$dest) !== false) {
$path = $dest;
} else {
return array('error_msg' => _('Failed to retrieve file from server!'));
}
break;
}
if (file_exists($path)) {
Oops, something went wrong.

0 comments on commit 84b4160

Please sign in to comment.
You can’t perform that action at this time.