コード例 #1
0
ファイル: core.php プロジェクト: verbazend/AWFA
 function remote_send_s3($accesskey, $secretkey, $bucket, $directory = '', $ssl, $file, $limit = 0, $send_importbuddy = false)
 {
     pb_backupbuddy::status('details', 'Starting Amazon S3 transfer.');
     require_once pb_backupbuddy::plugin_path() . '/lib/s3/s3.php';
     $s3 = new pb_backupbuddy_S3($accesskey, $secretkey, $ssl);
     // Set bucket with permissions.
     pb_backupbuddy::status('details', 'About to put bucket `' . $bucket . '` to Amazon S3 cron.');
     $s3->putBucket($bucket, pb_backupbuddy_S3::ACL_PRIVATE);
     pb_backupbuddy::status('details', 'About to put object `' . basename($file) . '` to Amazon S3 cron.');
     if (!empty($directory)) {
         $directory = $directory . '/';
     }
     // Send file.
     if (true === ($s3_response = $s3->putObject(pb_backupbuddy_S3::inputFile($file), $bucket, $directory . basename($file), pb_backupbuddy_S3::ACL_PRIVATE))) {
         pb_backupbuddy::status('details', 'SUCCESS sending to Amazon S3! Response: ' . $s3_response);
         if ($send_importbuddy === true) {
             pb_backupbuddy::status('details', 'Sending importbuddy to S3 based on settings.');
             $importbuddy_temp = pb_backupbuddy::$options['temp_directory'] . 'importbuddy_' . pb_backupbuddy::random_string(10) . '.php.tmp';
             // Full path & filename to temporary importbuddy
             $this->importbuddy($importbuddy_temp);
             // Create temporary importbuddy.
             $s3->putObject(pb_backupbuddy_S3::inputFile($importbuddy_temp), $bucket, $directory . 'importbuddy.php', pb_backupbuddy_S3::ACL_PRIVATE);
             @unlink($importbuddy_temp);
             // Delete temporary importbuddy.
         }
         // Start remote backup limit
         if ($limit > 0) {
             $results = $s3->getBucket($bucket);
             // Create array of backups and organize by date
             $bkupprefix = $this->backup_prefix();
             $backups = array();
             foreach ($results as $rekey => $reval) {
                 $pos = strpos($rekey, $directory . 'backup-' . $bkupprefix . '-');
                 if ($pos !== FALSE) {
                     $backups[$rekey] = $results[$rekey]['time'];
                 }
             }
             arsort($backups);
             if (count($backups) > $limit) {
                 $i = 0;
                 $delete_fail_count = 0;
                 foreach ($backups as $buname => $butime) {
                     $i++;
                     if ($i > $limit) {
                         if (!$s3->deleteObject($bucket, $buname)) {
                             pb_backupbuddy::status('details', 'Unable to delete excess S3 file `' . $buname . '` in bucket `' . $bucket . '`.');
                             $delete_fail_count++;
                         }
                     }
                 }
                 if ($delete_fail_count !== 0) {
                     $this->mail_error(sprintf(__('Amazon S3 remote limit could not delete %s backups.', 'it-l10n-backupbuddy'), $delete_fail_count));
                 }
             }
         } else {
             pb_backupbuddy::status('details', 'No S3 file limit to enforce.');
         }
         // End remote backup limit
         return true;
         // Success
     } else {
         // Failed.
         $error_message = 'ERROR #9024: Connected to Amazon S3 but unable to put file. There is a problem with one of the following S3 settings: bucket, directory, or S3 permissions. Details:' . "\n\n" . $s3_response . "\n\n" . 'http://ithemes.com/codex/page/BackupBuddy:_Error_Codes#9024';
         $this->mail_error(__($error_message, 'it-l10n-backupbuddy'));
         pb_backupbuddy::status('details', $error_message, 'error');
         return false;
         // Failed.
     }
 }
コード例 #2
0
ファイル: init.php プロジェクト: mariakhair/bootstrap
 public static function send($settings = array(), $files = array())
 {
     $accesskey = $settings['accesskey'];
     $secretkey = $settings['secretkey'];
     $bucket = $settings['bucket'];
     $directory = $settings['directory'];
     $ssl = $settings['ssl'];
     $storage_class = $settings['storage_class'];
     $server_encryption = $settings['server_encryption'];
     $limit = $settings['archive_limit'];
     // Add trailing slash to end of directory if one defined.
     if ($directory != '') {
         $directory = rtrim($directory, '/\\') . '/';
     }
     require_once dirname(__FILE__) . '/lib/s3.php';
     $s3 = new pb_backupbuddy_S3($accesskey, $secretkey, $ssl);
     // Set bucket with permissions.
     pb_backupbuddy::status('details', 'About to create S3 bucket `' . $bucket . '`.');
     $s3->putBucket($bucket, pb_backupbuddy_S3::ACL_PRIVATE);
     pb_backupbuddy::status('details', 'Bucket created.');
     // Send each file.
     foreach ($files as $file) {
         // Send file.
         if (false === pb_backupbuddy_S3::inputFile($file)) {
             pb_backupbuddy::status('error', 'Error #3443434: Bad input. File not found or access denied. Verify permissions.');
             return false;
         }
         pb_backupbuddy::status('details', 'Using S3 storage class `' . $storage_class . '`.');
         // TODO: adding this header does NOT work properly... gives signature errors...
         $meta = array();
         if ($server_encryption != '') {
             // Add encryption header if enabled.
             $meta['x-amz-server-side-encryption'] = $server_encryption;
         }
         pb_backupbuddy::status('details', 'About to put file to S3.');
         $s3_response = $s3->putObject(pb_backupbuddy_S3::inputFile($file), $bucket, $directory . basename($file), pb_backupbuddy_S3::ACL_PRIVATE, array(), $meta);
         // , $storage_class
         if ($s3_response !== true) {
             // Failed.
             $error_message = 'ERROR #9024: Connected to Amazon S3 but unable to put file. There is a problem with one of the following S3 settings: bucket, directory, or S3 permissions. Details:' . "\n\n" . $s3_response . "\n\n" . 'http://ithemes.com/codex/page/BackupBuddy:_Error_Codes#9024';
             pb_backupbuddy::status('details', $error_message, 'error');
             pb_backupbuddy::$classes['core']->mail_error(__($error_message, 'it-l10n-backupbuddy'));
             return false;
             // Failed.
         } else {
             pb_backupbuddy::status('details', 'File put successfully.');
         }
         // Success sending this file if we made it this far.
         pb_backupbuddy::status('details', 'SUCCESS sending to Amazon S3! Response: ' . $s3_response);
         // Start remote backup limit
         if ($limit > 0) {
             pb_backupbuddy::status('details', 'Archive limit of `' . $limit . '` in settings.');
             $results = $s3->getBucket($bucket);
             // Create array of backups and organize by date
             $bkupprefix = pb_backupbuddy::$classes['core']->backup_prefix();
             $backups = array();
             foreach ($results as $rekey => $reval) {
                 $pos = strpos($rekey, $directory . 'backup-' . $bkupprefix . '-');
                 if ($pos !== FALSE) {
                     $backups[$rekey] = $results[$rekey]['time'];
                 }
             }
             arsort($backups);
             if (count($backups) > $limit) {
                 pb_backupbuddy::status('details', 'More archives (' . count($backups) . ') than limit (' . $limit . ') allows. Trimming...');
                 $i = 0;
                 $delete_fail_count = 0;
                 foreach ($backups as $buname => $butime) {
                     $i++;
                     if ($i > $limit) {
                         pb_backupbuddy::status('details', 'Trimming excess file `' . $buname . '`...');
                         if (!$s3->deleteObject($bucket, $buname)) {
                             pb_backupbuddy::status('details', 'Unable to delete excess S3 file `' . $buname . '` in bucket `' . $bucket . '`.');
                             $delete_fail_count++;
                         }
                     }
                 }
                 pb_backupbuddy::status('details', 'Finished trimming excess backups.');
                 if ($delete_fail_count !== 0) {
                     $error_message = 'Amazon S3 remote limit could not delete ' . $delete_fail_count . ' backups.';
                     pb_backupbuddy::status('error', $error_message);
                     pb_backupbuddy::$classes['core']->mail_error($error_message);
                 }
             }
         } else {
             pb_backupbuddy::status('details', 'No S3 file limit to enforce.');
         }
         // End remote backup limit
     }
     // end foreach file.
     // Success sending all files if we made it this far.
     return true;
 }