Exemplo n.º 1
0
 function remote_send_dropbox($token, $directory, $file, $limit = 0, $send_importbuddy = false)
 {
     // Normalize picky dropbox directory.
     $directory = trim($directory, '\\/');
     $directory = str_replace(' ', '%20', $directory);
     pb_backupbuddy::status('details', 'Starting Dropbox transfer.');
     require_once pb_backupbuddy::plugin_path() . '/lib/dropbuddy/dropbuddy.php';
     $dropbuddy = new pb_backupbuddy_dropbuddy($token);
     if ($dropbuddy->authenticate() !== true) {
         pb_backupbuddy::status('details', 'Dropbox authentication failed in remote_send_dropbox.');
         return false;
     }
     pb_backupbuddy::status('details', 'About to put object `' . basename($file) . '` to Dropbox cron.');
     $status = $dropbuddy->put_file($directory . '/' . basename($file), $file);
     if ($status === true) {
         pb_backupbuddy::status('details', 'SUCCESS sending to Dropbox!');
     } else {
         pb_backupbuddy::status('details', 'Dropbox file send FAILURE. HTTP Status: ' . $status['httpStatus'] . '; Body: ' . $status['body'], 'error');
         return false;
     }
     // Handle sending importbuddy.php.
     if ($send_importbuddy === true) {
         pb_backupbuddy::status('details', 'Sending importbuddy to Dropbox 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.
         $dropbuddy->put_file($directory . '/' . basename($file), $file);
         @unlink($importbuddy_temp);
         // Delete temporary importbuddy.
     }
     // Start remote backup limit
     if ($limit > 0) {
         pb_backupbuddy::status('details', 'Dropbox file limit in place. Proceeding with enforcement.');
         $meta_data = $dropbuddy->get_meta_data($directory);
         // Create array of backups and organize by date
         $bkupprefix = $this->backup_prefix();
         $backups = array();
         foreach ((array) $meta_data['contents'] as $file) {
             // check if file is backup
             if (strpos($file['path'], 'backup-' . $bkupprefix . '-') !== FALSE) {
                 $backups[$file['path']] = strtotime($file['modified']);
             }
         }
         arsort($backups);
         if (count($backups) > $limit) {
             pb_backupbuddy::status('details', 'Dropbox backup file count of `' . count($backups) . '` exceeds limit of `' . $limit . '`.');
             $i = 0;
             $delete_fail_count = 0;
             foreach ($backups as $buname => $butime) {
                 $i++;
                 if ($i > $limit) {
                     if (!$dropbuddy->delete($buname)) {
                         // Try to delete backup on Dropbox. Increment failure count if unable to.
                         pb_backupbuddy::status('details', 'Unable to delete excess Dropbox file: `' . $buname . '`');
                         $delete_fail_count++;
                     }
                 }
             }
             if ($delete_fail_count !== 0) {
                 $this->mail_error(sprintf(__('Dropbox remote limit could not delete %s backups.', 'it-l10n-backupbuddy'), $delete_fail_count));
             }
         }
     } else {
         pb_backupbuddy::status('details', 'No Dropbox file limit to enforce.');
     }
     // End remote backup limit
     return true;
     // Success if made it this far.
 }
Exemplo n.º 2
0
$meta_data = $dropbuddy->get_meta_data($destination['directory']);
/*
echo '<pre>';
print_r( $meta_data ) );
echo '</pre>';
*/
// Delete dropbox backups
if (!empty($_POST['delete_file'])) {
    pb_backupbuddy::verify_nonce();
    $delete_count = 0;
    if (!empty($_POST['files']) && is_array($_POST['files'])) {
        // loop through and delete dropbox files
        foreach ($_POST['files'] as $dropboxfile) {
            $delete_count++;
            // Delete dropbox file
            $dropbuddy->delete($dropboxfile);
        }
    }
    if ($delete_count > 0) {
        pb_backupbuddy::alert(sprintf(_n('Deleted %d file', 'Deleted %d files', $delete_count, 'it-l10n-backupbuddy'), $delete_count));
        $meta_data = $dropbuddy->get_meta_data($destination['directory']);
        // Refresh listing.
    }
}
// Copy dropbox backups to the local backup files
if (!empty($_GET['copy_file'])) {
    pb_backupbuddy::alert(sprintf(_x('The remote file is now being copied to your %1$slocal backups%2$s', '%1$s and %2$s are open and close <a> tags', 'it-l10n-backupbuddy'), '<a href="' . pb_backupbuddy::page_url() . '">', '</a>. If the backup gets marked as bad during copying, please wait a bit then click the `Refresh` icon to rescan after the transfer is complete.'));
    pb_backupbuddy::status('details', 'Scheduling Cron for creating Dropbox copy.');
    wp_schedule_single_event(time(), pb_backupbuddy::cron_tag('process_dropbox_copy'), array($_GET['destination_id'], $_GET['copy_file']));
    spawn_cron(time() + 150);
    // Adds > 60 seconds to get around once per minute cron running limit.
Exemplo n.º 3
0
 public static function send($settings = array(), $files = array())
 {
     $token =& $settings['token'];
     $directory = $settings['directory'];
     $limit = $settings['archive_limit'];
     // Normalize picky dropbox directory.
     $directory = trim($directory, '\\/');
     pb_backupbuddy::status('details', 'About to load Dropbuddy library...');
     require_once pb_backupbuddy::plugin_path() . '/destinations/dropbox/lib/dropbuddy/dropbuddy.php';
     pb_backupbuddy::status('details', 'Dropbuddy loaded.');
     //pb_backupbuddy::status( 'details', 'Authenticating to dropbox with token: `' . implode( ';', $token ) . '`.' );
     $dropbuddy = new pb_backupbuddy_dropbuddy($token);
     pb_backupbuddy::status('details', 'Dropbuddy object created.');
     if ($dropbuddy->authenticate() !== true) {
         pb_backupbuddy::status('details', 'Dropbox authentication failed in send().');
         return false;
     } else {
         pb_backupbuddy::status('details', 'Authenticated to Dropbox.');
     }
     pb_backupbuddy::status('details', 'Looping through files to send to Dropbox.');
     foreach ($files as $file) {
         pb_backupbuddy::status('details', 'About to put object `' . basename($file) . '` to Dropbox cron.');
         try {
             $status = $dropbuddy->put_file($directory . '/' . basename($file), $file);
         } catch (Dropbox_Exception $e) {
             pb_backupbuddy::status('error', 'Dropbox exception caught. Error #8954785: ' . $e->getMessage());
             return false;
         }
         if ($status === true) {
             pb_backupbuddy::status('details', 'SUCCESS sending to Dropbox!');
         } else {
             pb_backupbuddy::status('details', 'Dropbox file send FAILURE. HTTP Status: ' . $status['httpStatus'] . '; Body: ' . $status['body'], 'error');
             return false;
         }
         // Start remote backup limit
         if ($limit > 0) {
             pb_backupbuddy::status('details', 'Dropbox file limit in place. Proceeding with enforcement.');
             $meta_data = $dropbuddy->get_meta_data($directory);
             // Create array of backups and organize by date
             $bkupprefix = pb_backupbuddy::$classes['core']->backup_prefix();
             $backups = array();
             foreach ((array) $meta_data['contents'] as $looping_file) {
                 // check if file is backup
                 if (strpos($looping_file['path'], 'backup-' . $bkupprefix . '-') !== false) {
                     $backups[$looping_file['path']] = strtotime($looping_file['modified']);
                 }
             }
             arsort($backups);
             if (count($backups) > $limit) {
                 pb_backupbuddy::status('details', 'Dropbox backup file count of `' . count($backups) . '` exceeds limit of `' . $limit . '`.');
                 $i = 0;
                 $delete_fail_count = 0;
                 foreach ($backups as $buname => $butime) {
                     $i++;
                     if ($i > $limit) {
                         if (!$dropbuddy->delete($buname)) {
                             // Try to delete backup on Dropbox. Increment failure count if unable to.
                             pb_backupbuddy::status('details', 'Unable to delete excess Dropbox file: `' . $buname . '`');
                             $delete_fail_count++;
                         }
                     }
                 }
                 if ($delete_fail_count !== 0) {
                     pb_backupbuddy::$classes['core']->mail_error(sprintf(__('Dropbox remote limit could not delete %s backups.', 'it-l10n-backupbuddy'), $delete_fail_count));
                 }
             }
         } else {
             pb_backupbuddy::status('details', 'No Dropbox file limit to enforce.');
         }
         // End remote backup limit
     }
     // end foreach.
     pb_backupbuddy::status('details', 'All files sent.');
     return true;
     // Success if made it this far.
 }
Exemplo n.º 4
0
 public static function send($settings = array(), $files = array(), $send_id = '')
 {
     global $pb_backupbuddy_destination_errors;
     if ('1' == $settings['disabled']) {
         $pb_backupbuddy_destination_errors[] = __('Error #48933: This destination is currently disabled. Enable it under this destination\'s Advanced Settings.', 'it-l10n-backupbuddy');
         return false;
     }
     if (!is_array($files)) {
         $files = array($files);
     }
     $token =& $settings['token'];
     $directory = '/' . ltrim($settings['directory'], '/\\');
     $limit = $settings['archive_limit'];
     // Normalize picky dropbox directory.
     $directory = trim($directory, '\\/');
     pb_backupbuddy::status('details', 'About to load Dropbuddy library...');
     require_once pb_backupbuddy::plugin_path() . '/destinations/dropbox/lib/dropbuddy/dropbuddy.php';
     pb_backupbuddy::status('details', 'Dropbuddy loaded.');
     //pb_backupbuddy::status( 'details', 'Authenticating to dropbox with token: `' . implode( ';', $token ) . '`.' );
     $dropbuddy = new pb_backupbuddy_dropbuddy($token);
     pb_backupbuddy::status('details', 'Dropbuddy object created.');
     if ($dropbuddy->authenticate() !== true) {
         pb_backupbuddy::status('details', 'Dropbox authentication failed in send().');
         return false;
     } else {
         pb_backupbuddy::status('details', 'Authenticated to Dropbox.');
     }
     $memory = pb_backupbuddy_destination_dropbox::memory_guesstimate();
     pb_backupbuddy::status('details', 'Dropbox limitation estimated to be max transfer size of ' . round($memory['hypothesis'], 0) . 'MB based on PHP memory limit of ' . $memory['limit'] . 'MB & current loaded WordPress plugins.');
     pb_backupbuddy::status('details', 'Looping through files to send to Dropbox.');
     foreach ($files as $file) {
         pb_backupbuddy::status('details', 'About to put file `' . basename($file) . '` (' . pb_backupbuddy::$format->file_size(filesize($file)) . ') to Dropbox (v1).');
         try {
             $status = $dropbuddy->put_file($directory . '/' . basename($file), $file);
         } catch (Dropbox_Exception $e) {
             pb_backupbuddy::status('error', 'Dropbox exception caught. Error #8954785: ' . $e->getMessage());
             return false;
         }
         if ($status === true) {
             pb_backupbuddy::status('details', 'SUCCESS sending to Dropbox!');
         } else {
             pb_backupbuddy::status('details', 'Dropbox file send FAILURE. HTTP Status: ' . $status['httpStatus'] . '; Body: ' . $status['body'], 'error');
             return false;
         }
         // Start remote backup limit
         if ($limit > 0) {
             pb_backupbuddy::status('details', 'Dropbox file limit in place. Proceeding with enforcement.');
             $meta_data = $dropbuddy->get_meta_data($directory);
             // Create array of backups and organize by date
             $bkupprefix = backupbuddy_core::backup_prefix();
             $backups = array();
             foreach ((array) $meta_data['contents'] as $looping_file) {
                 if ('1' == $looping_file['is_dir']) {
                     // Additional safety layer to ignore subdirectory.
                     continue;
                 }
                 // check if file is backup
                 if (strpos($looping_file['path'], 'backup-' . $bkupprefix . '-') !== false) {
                     $backups[$looping_file['path']] = strtotime($looping_file['modified']);
                 }
             }
             arsort($backups);
             if (count($backups) > $limit) {
                 pb_backupbuddy::status('details', 'Dropbox backup file count of `' . count($backups) . '` exceeds limit of `' . $limit . '`.');
                 $i = 0;
                 $delete_fail_count = 0;
                 foreach ($backups as $buname => $butime) {
                     $i++;
                     if ($i > $limit) {
                         if (!$dropbuddy->delete($buname)) {
                             // Try to delete backup on Dropbox. Increment failure count if unable to.
                             pb_backupbuddy::status('details', 'Unable to delete excess Dropbox file: `' . $buname . '`');
                             $delete_fail_count++;
                         }
                     }
                 }
                 if ($delete_fail_count !== 0) {
                     backupbuddy_core::mail_error(sprintf(__('Dropbox remote limit could not delete %s backups.', 'it-l10n-backupbuddy'), $delete_fail_count));
                 }
             }
         } else {
             pb_backupbuddy::status('details', 'No Dropbox file limit to enforce.');
         }
         // End remote backup limit
     }
     // end foreach.
     pb_backupbuddy::status('details', 'All files sent.');
     return true;
     // Success if made it this far.
 }