public/wordpress/wp-content/plugins/backupbuddy/destinations/s3/init.php
/* multipart_cleanup()
	 *
	 * S3 does NOT automatically clean up failred or expired multipart chunk files so clean up for them.
	 *
	 */
multipart_cleanup()
S3 does NOT automatically clean up failred or expired multipart chunk files so clean up for them.
multipart_cleanup () S3 does NOT automatically clean up failred or expired multipart chunk files so clean up for them .
public static function multipart_cleanup( $settings, $lessLogs = true ) {
		$settings['bucket'] = strtolower( $settings['bucket'] ); 
		$max_age = 60*60*72; 
		require_once( dirname( dirname( __FILE__ ) ) . '/_s3lib/aws-sdk/sdk.class.php' );
		pb_backupbuddy::status( 'details', 'Amazon S3 Multipart Remote Housekeeping Starting ...' );
		$manage_data = pb_backupbuddy_destination_s3::get_credentials( $settings );
		pb_backupbuddy::status( 'details', 'Creating S3 instance.' );
		$s3 = new AmazonS3( $manage_data );    
		if ( $settings['ssl'] == 0 ) {
			@$s3->disable_ssl(true);
		}
		pb_backupbuddy::status( 'details', 'S3 instance created. Listing in progress multipart uploads ...' );
		if ( false === self::_prepareBucketAndRegion( $s3, $settings, $createBucket = false ) ) {
			return false;
		}
		$response = $s3->list_multipart_uploads(
			$settings['bucket'],
			array(
				'prefix' => 'backup',
			)
		);
		if(!$response->isOK()) {
			pb_backupbuddy::status( 'error', 'Error listing multipart uploads. Details: `' . print_r( $response, true ) . '`' );
			return;
		} else {
			if ( true !== $lessLogs ) {
				pb_backupbuddy::status( 'details', 'Multipart upload check retrieved. Found `' . count( $response->body->Upload ) . '` multipart uploads in progress / stalled. Details: `' . print_r( $response, true ) . '`' );
			} else {
				pb_backupbuddy::status( 'details', 'Multipart upload check retrieved. Found `' . count( $response->body->Upload ) . '` multipart uploads in progress / stalled. Old BackupBuddy parts will be cleaned up (if any found) ...' );
			}
			foreach( $response->body->Upload as $upload ) {
				if ( true !== $lessLogs ) {
					pb_backupbuddy::status( 'details', 'Checking upload: ' . print_r( $upload, true ) );
				}
				if ( FALSE !== stristr( $upload->Key, 'backup-' ) ) { 
					$initiated = strtotime( $upload->Initiated );
					if ( true !== $lessLogs ) {
						pb_backupbuddy::status( 'details', 'BackupBuddy Multipart Chunked Upload(s) detected in progress. Age: `' . pb_backupbuddy::$format->time_ago( $initiated ) . '`.' );
					}
					if ( ( $initiated + $max_age ) < time() ) {
						$abort_response = $s3->abort_multipart_upload( $settings['bucket'], $upload->Key, $upload->UploadId );
						if(!$abort_response->isOK()) { 
							pb_backupbuddy::status( 'error', 'Stalled Amazon S3 Multipart Chunked abort of file `' . $upload->Key . '` with ID `' . $upload->UploadId . '` FAILED. Manually abort it.' );
						} else { 
							pb_backupbuddy::status( 'details', 'Stalled Amazon S3 Multipart Chunked Uploads ABORTED ID `' . $upload->UploadId . '` of age `' . pb_backupbuddy::$format->time_ago( $initiated ) . '`.' );
						}
					} else {
						if ( true !== $lessLogs ) {
							pb_backupbuddy::status( 'details', 'Amazon S3 Multipart Chunked Uploads not aborted as not too old.' );
						}
					}
				}
			} 
		}
		pb_backupbuddy::status( 'details', 'Amazon S3 Multipart Remote Housekeeping Finished.' );
		return true;
	}
public static function multipart_cleanup ( $ settings , $ lessLogs = true ) { $ settings [ 'bucket' ] = strtolower ( $ settings [ 'bucket' ] ) ; $ max_age = 60 * 60 * 72 ; require_once ( dirname ( dirname ( __FILE__ ) ) . '/_s3lib/aws-sdk/sdk.class.php' ) ; pb_backupbuddy :: status ( 'details' , 'Amazon S3 Multipart Remote Housekeeping Starting ...' ) ; $ manage_data = pb_backupbuddy_destination_s3 :: get_credentials ( $ settings ) ; pb_backupbuddy :: status ( 'details' , 'Creating S3 instance.' ) ; $ s3 = new AmazonS3 ( $ manage_data ) ; if ( $ settings [ 'ssl' ] == 0 ) { @ $ s3 -> disable_ssl ( true ) ; } pb_backupbuddy :: status ( 'details' , 'S3 instance created. Listing in progress multipart uploads ...' ) ; if ( false === self :: _prepareBucketAndRegion ( $ s3 , $ settings , $ createBucket = false ) ) { return false ; } $ response = $ s3 -> list_multipart_uploads ( $ settings [ 'bucket' ] , array ( 'prefix' => 'backup' , ) ) ; if ( ! $ response -> isOK ( ) ) { pb_backupbuddy :: status ( 'error' , 'Error listing multipart uploads. Details: `' . print_r ( $ response , true ) . '`' ) ; return ; } else { if ( true !== $ lessLogs ) { pb_backupbuddy :: status ( 'details' , 'Multipart upload check retrieved. Found `' . count ( $ response -> body -> Upload ) . '` multipart uploads in progress / stalled. Details: `' . print_r ( $ response , true ) . '`' ) ; } else { pb_backupbuddy :: status ( 'details' , 'Multipart upload check retrieved. Found `' . count ( $ response -> body -> Upload ) . '` multipart uploads in progress / stalled. Old BackupBuddy parts will be cleaned up (if any found) ...' ) ; } foreach ( $ response -> body -> Upload as $ upload ) { if ( true !== $ lessLogs ) { pb_backupbuddy :: status ( 'details' , 'Checking upload: ' . print_r ( $ upload , true ) ) ; } if ( FALSE !== stristr ( $ upload -> Key , 'backup-' ) ) { $ initiated = strtotime ( $ upload -> Initiated ) ; if ( true !== $ lessLogs ) { pb_backupbuddy :: status ( 'details' , 'BackupBuddy Multipart Chunked Upload(s) detected in progress. Age: `' . pb_backupbuddy :: $ format -> time_ago ( $ initiated ) . '`.' ) ; } if ( ( $ initiated + $ max_age ) < time ( ) ) { $ abort_response = $ s3 -> abort_multipart_upload ( $ settings [ 'bucket' ] , $ upload -> Key , $ upload -> UploadId ) ; if ( ! $ abort_response -> isOK ( ) ) { pb_backupbuddy :: status ( 'error' , 'Stalled Amazon S3 Multipart Chunked abort of file `' . $ upload -> Key . '` with ID `' . $ upload -> UploadId . '` FAILED. Manually abort it.' ) ; } else { pb_backupbuddy :: status ( 'details' , 'Stalled Amazon S3 Multipart Chunked Uploads ABORTED ID `' . $ upload -> UploadId . '` of age `' . pb_backupbuddy :: $ format -> time_ago ( $ initiated ) . '`.' ) ; } } else { if ( true !== $ lessLogs ) { pb_backupbuddy :: status ( 'details' , 'Amazon S3 Multipart Chunked Uploads not aborted as not too old.' ) ; } } } } } pb_backupbuddy :: status ( 'details' , 'Amazon S3 Multipart Remote Housekeeping Finished.' ) ; return true ; }
multipart_cleanup()
 S3 does NOT automatically clean up failred or expired multipart chunk files so clean up for them.
multipart_cleanup () S3 does NOT automatically clean up failred or expired multipart chunk files so clean up for them .
// Buckets must be lowercase. // Seconds of max age to allow a stalled multipart upload. // Create S3 instance. // the key, secret, token // Verify bucket exists; create if not. Also set region to the region bucket exists in. // Get the in progress multipart uploads //'prefix' => $settings['_multipart_remotefile'], // BackupBuddy backup file. // abort fail. // aborted. // end foreach uploads.