public function backup()
 {
     $options = Sns_Option::get_options();
     $backupItems = array();
     // self::configureCount( $options[Sns_Option::COUNT]->value );
     if ($options[Sns_Option::WP_CONTENT]->value == Sns_Option::SET) {
         $backupItems[Sns_Option::WP_CONTENT] = WP_CONTENT_DIR;
     } else {
         if ($options[Sns_Option::PLUGINS]->value == Sns_Option::SET) {
             $backupItems[Sns_Option::PLUGINS] = WP_PLUGIN_DIR;
         }
         if ($options[Sns_Option::THEMES]->value == Sns_Option::SET) {
             $backupItems[Sns_Option::THEMES] = get_theme_root();
         }
     }
     if ($options[Sns_Option::DB]->value == Sns_Option::SET) {
         $backupItems[Sns_Option::DB] = Sns_Option::SET;
     }
     $notification = new Sns_Notification();
     try {
         @session_write_close();
         $warns = $this->backup_items($backupItems);
         Sns_Log::log_msg('[SUCCEED Backup]' . PHP_EOL);
         $destinations = new Sns_Destination($this->type);
         $locations = $destinations->get_destinations();
         $filePath = SNS_BACKUPS_PATH . $this->filename . '.zip';
         if ($locations[Sns_Destination::SETTINGS_FTP]->status == Sns_Destination::SET) {
             Sns_Log::log_action('Uploading to FTP server');
             try {
                 $ftp = new Sns_Ftp();
                 $ftp->upload($filePath, $this->filename . '.zip');
             } catch (Exception $e) {
                 Sns_Exception_Handler::log($e);
             }
             Sns_Log::log_action('Uploading to FTP server', SNS_LOG_END);
         }
         return $warns;
     } catch (Exception $e) {
         Sns_Log::log_exception_obj($e);
         Sns_Log::log_msg('[FAILED Backup]');
         Sns_History::delete_by_hash($this->hash, $this->filename);
         throw $e;
     }
 }
function sns_backup_uninstall()
{
    //drop sns backup plugins tables
    global $wpdb;
    $table = SNS_DB_PREFIX . 'settings_destinations';
    $wpdb->query("DROP TABLE IF EXISTS `{$table}`");
    $table = SNS_DB_PREFIX . 'settings_notifications';
    $wpdb->query("DROP TABLE IF EXISTS `{$table}`");
    $table = SNS_DB_PREFIX . 'backups';
    $wpdb->query("DROP TABLE IF EXISTS `{$table}`");
    $table = SNS_DB_PREFIX . 'options';
    $wpdb->query("DROP TABLE IF EXISTS `{$table}`");
    $table = SNS_DB_PREFIX . 'schedule_config';
    $wpdb->query("DROP TABLE IF EXISTS `{$table}`");
    $table = SNS_DB_PREFIX . 'settings_ftp';
    $wpdb->query("DROP TABLE IF EXISTS `{$table}`");
    $table = SNS_DB_PREFIX . 'state';
    $wpdb->query("DROP TABLE IF EXISTS `{$table}`");
    $table = SNS_DROPBOX_TABLE;
    $wpdb->query("DROP TABLE IF EXISTS `{$table}`");
    //delete backup files
    if (is_dir(SNS_BACKUPS_PATH)) {
        Sns_History::delete_dir(SNS_BACKUPS_PATH);
    }
    delete_option('sns_backup_version');
    delete_option('sns_backup_review_off');
}
 public static function delete_by_hash($hash, $filename)
 {
     global $wpdb;
     $table = SNS_DB_PREFIX . 'backups';
     $query = " DELETE FROM `{$table}`\n                       WHERE `hash` = '{$hash}'\n                      ";
     $response = $wpdb->query($query);
     if ($response === false) {
         throw new Sns_Exception_DB_Error();
     }
     $backupFile = SNS_BACKUPS_PATH . $filename . '.zip';
     if (is_file($backupFile) && !unlink($backupFile)) {
         throw new Sns_Exception_Unavailable_Operation('Cannot delete the file ' . $backupFile);
     }
     $backupDir = SNS_BACKUPS_PATH . $filename;
     if (is_dir($backupDir)) {
         Sns_History::delete_dir($backupDir);
     }
 }
                            <form class="manual-form" autocomplete="off" role="form" action="">
                                <?php 
$destination = new Sns_Destination(Sns_Backup::BACKUP_MODE_MANUAL);
$destination->draw();
?>
                                <div class="separator"></div>
                                <div class="cb"></div>
                                <div id="progressbar-backup"><div class="progress-label"></div></div>

                                <button type="submit" class="btn btn-primary sns-action">Backup</button>
                            </form>
                        </div>
                    </div>
                    <div id="menu-tab-history">
                        <?php 
Sns_History::draw();
?>
                    </div>
                    <div id="menu-tab-schedule">
                        <?php 
Sns_Schedule::draw();
?>
                    </div>
                    <div id="menu-tab-settings">
                        <div id="settings-tabs">
                            <div class="settings-items">
                                <ul>
                                    <li class="settings-item"><a href="#settings-tab-options">Options <?php 
echo SNS_PRO_TOOLTIP;
?>
</a></li>
function sns_backup_external_restore($uname)
{
    try {
        Sns_Log::log_msg('########PROCESS STARTED########' . PHP_EOL);
        $state = Sns_State::get_status();
        if ($state['status'] == Sns_State::STATUS_ACTIVE) {
            throw new Sns_Exception_Unavailable_Operation('There is an existing active process.Please wait.');
        }
        $stateData = array('status' => Sns_State::STATUS_ACTIVE, 'type' => Sns_State::TYPE_RESTORE, 'start_date' => date('Y-m-d H:i:s'));
        Sns_State::update($stateData);
        try {
            $file_dir = dirname(__FILE__) . SNS_DS . 'sns_backup-external-' . $uname . '.zip';
            if (!file_exists($file_dir)) {
                throw new Sns_Exception_Not_Found('File not found');
            }
            $backup_dir = substr($file_dir, 0, strlen($file_dir) - 4);
            Sns_Log::log_action('Restoring from external file');
            Sns_History::restore_from_file($backup_dir, $file_dir);
            Sns_Log::log_action('Restoring from external file', SNS_LOG_END);
            @unlink($file_dir);
            Sns_Log::log_msg('[SUCCEED Restore]' . PHP_EOL);
        } catch (Exception $e) {
            Sns_Log::log_msg('[FAILED Restore]' . PHP_EOL);
            throw $e;
        }
        $stateData = array('status' => Sns_State::STATUS_FINISHED, 'type' => Sns_State::TYPE_RESTORE);
        Sns_State::update($stateData);
        Sns_Log::log_msg('########PROCESS ENDED########' . PHP_EOL);
    } catch (Exception $e) {
        Sns_Log::log_exception_obj($e);
        $ex_data = Sns_Exception_Handler::get_exception_data($e);
        $stateData = array('status' => Sns_State::STATUS_FAILED, 'type' => Sns_State::TYPE_RESTORE, 'msg' => $ex_data['status'] . ' : ' . $ex_data['msg']);
        Sns_State::update($stateData);
        Sns_Log::log_msg('########PROCESS ENDED########' . PHP_EOL);
        Sns_Log::report('restore');
        wp_redirect(admin_url("admin.php?page=" . $_GET['page']));
    }
}