if ($GLOBALS["VERBOSE"]) {
    "echo Loading...\n";
}
include_once dirname(__FILE__) . '/ressources/class.templates.inc';
include_once dirname(__FILE__) . '/ressources/class.ini.inc';
include_once dirname(__FILE__) . '/ressources/class.mysql.inc';
include_once dirname(__FILE__) . '/framework/class.unix.inc';
include_once dirname(__FILE__) . '/ressources/class.squid.inc';
include_once dirname(__FILE__) . '/ressources/class.os.system.inc';
include_once dirname(__FILE__) . "/framework/frame.class.inc";
include_once dirname(__FILE__) . '/ressources/class.artica-meta.inc';
include_once dirname(__FILE__) . '/ressources/class.computers.inc';
include_once dirname(__FILE__) . '/ressources/class.mysql.stats-appliance.inc';
include_once dirname(__FILE__) . '/ressources/class.parse.berekley.inc';
if ($argv[1] == "--db") {
    db_dump($argv[2]);
    die;
}
parse();
function parse()
{
    $TimeFile = "/etc/artica-postfix/pids/exec.squid.stats.quota-week.parser.php.time";
    $pidfile = "/etc/artica-postfix/pids/exec.squid.stats.quota-week.parser.php.pid";
    $unix = new unix();
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["VERBOSE"]) {
            echo "{$pid} already executed since {$timepid}Mn\n";
        }
        if ($timepid < 14) {
Example #2
0
/**
* "Deletes" a database: makes a .sql dump of the database content
* and zips all files related to this db.
*
* @param mixed $db Database name WITHOUT hdb extension
*/
function db_delete($db, $verbose = true)
{
    if (db_dump($db)) {
        // Create DELETED_DATABASES directory if needed
        $folder = HEURIST_UPLOAD_ROOT . "DELETED_DATABASES/";
        if (!file_exists($folder)) {
            mkdir($folder, 0777, true);
        }
        // Zip $source to $file
        $source = HEURIST_UPLOAD_ROOT . $db;
        $destination = $folder . $db . "_" . time() . ".zip";
        if (zip($source, $destination)) {
            // Delete $source folder
            deleteFolder($source);
            if ($verbose) {
                echo "<br/>Folder " . $source . " has been deleted";
            }
            // Delete from MySQL
            $mysqli = server_connect();
            $mysqli->query("DROP DATABASE hdb_" . $db);
            $mysqli->close();
            if ($verbose) {
                echo "<br/>Database " . $db . " has been dropped";
            }
            return true;
        } else {
            if ($verbose) {
                echo "<br/>Failed to zip " . $source . " to " . $destination;
            }
        }
    } else {
        if ($verbose) {
            echo "<br/>Failed to dump database " . $db . " to a .sql file";
        }
    }
    return false;
}
Example #3
0
 /**
  * Initiates the backup procedure.
  *
  * @global string  $wp_version WordPress version
  */
 public function do_backup($id = '')
 {
     global $wp_version;
     $used_memory = memory_get_usage(true);
     // Get the memory usage before we do anything.
     if ($id) {
         $this->log_file = $this->options['backup_list'][$id]['log'];
     } else {
         $id = base_convert($this->time, 10, 36);
         $this->log_file = $this->local_folder . '/' . $id . '.log';
         file_put_contents($this->log_file, "#Fields:\tdate\ttime\ttype\tmessage\n");
         $this->options['backup_list'][$id] = array('timestamp' => $this->time, 'title' => $this->options['backup_title'] . ' (' . $id . ')', 'file_path' => '', 'drive_id' => '', 'log' => $this->log_file, 'attempt' => 0);
         // Save info about our new backup now, so we can have access to the log file even if MySQL connection is stolen.
         update_option('backup_options', $this->options);
         // Log environment information.
         if (!($z = phpversion('zip'))) {
             $z = 'false';
         }
         $c = '';
         if (in_array('curl', $this->options['enabled_transports']) && function_exists('curl_version')) {
             $c = curl_version();
             $c = '; CURL ' . $c['version'];
         }
         $env = "Environment: Backup " . $this->version . "; WordPress " . $wp_version . "; PHP " . phpversion() . "; SAPI " . php_sapi_name() . "; OS " . PHP_OS . "; ZIP " . $z . $c;
         if ((bool) ini_get('safe_mode')) {
             $env .= "; Safe mode ON";
         }
         $env .= "; Time limit " . ini_get('max_execution_time') . "s" . "; Memory limit " . ini_get('memory_limit');
         $this->log("NOTICE", $env);
     }
     // We can't hook to WP's shudown hook because we need to pass the $id.
     register_shutdown_function(array(&$this, 'handle_timeout'), $id);
     $file_name = sanitize_file_name($this->options['backup_list'][$id]['title']) . '.zip';
     $file_path = $this->local_folder . '/' . $file_name;
     if (@is_file($file_path)) {
         $this->options['backup_list'][$id]['file_path'] = $file_path;
     }
     if (empty($this->options['backup_list'][$id]['file_path'])) {
         // Check if the backup folder is writable
         if (!@is_dir($this->local_folder) && !$this->create_dir($this->local_folder) || !@is_writable($this->local_folder)) {
             $this->log('ERROR', sprintf(__("The directory '%s' does not exist or is not writable.", $this->text_domain), esc_html($this->local_folder)));
             $this->reschedule_backup($id);
         }
         // Create database dump sql file.
         if (in_array('database', $this->options['source_list'])) {
             $this->log('NOTICE', __('Attempting to dump database.', $this->text_domain));
             if (is_wp_error($dump_time = db_dump($this->dump_file))) {
                 $this->log_wp_error($dump_time);
                 $this->reschedule_backup($id);
             }
             $this->log('NOTICE', sprintf(__('The database dump was completed successfully in %s seconds.', $this->text_domain), number_format_i18n($dump_time, 3)));
         }
         // Merge the default exclude list with the user provided one and make them absolute paths.
         $exclude = array_merge($this->options['exclude_list'], $this->exclude);
         foreach ($exclude as $i => $path) {
             if (false !== strpos($path, '/') || false !== strpos($path, "\\")) {
                 $exclude[$i] = absolute_path($path, ABSPATH);
             }
         }
         // Create the source list from the user selected sources.
         $sources = array();
         foreach ($this->options['source_list'] as $source) {
             $sources[] = $this->sources[$source]['path'];
         }
         // Remove subdirectories from the sources.
         $count = count($sources);
         for ($i = 0; $i < $count; $i++) {
             for ($j = 0; $j < $count; $j++) {
                 if ($j != $i && isset($sources[$i]) && isset($sources[$j]) && is_subdir($sources[$j], $sources[$i]) && $this->sources['database']['path'] != $sources[$j]) {
                     unset($sources[$j]);
                 }
             }
         }
         // Transform include paths to absolute paths.
         $include = $this->options['include_list'];
         foreach ($include as $i => $path) {
             $include[$i] = absolute_path($path, ABSPATH);
         }
         // Merge the include list and the sources
         $sources = array_merge($sources, $include);
         // Create archive from the sources list.
         $this->log('NOTICE', sprintf(__("Attempting to create archive '%s'.", $this->text_domain), esc_html($file_name)));
         if (!phpversion('zip')) {
             define('PCLZIP_TEMPORARY_DIR', $this->local_folder);
         }
         if (is_wp_error($zip = zip($sources, $file_path, $exclude))) {
             $this->log_wp_error($zip);
             delete_path($this->dump_file);
             $this->reschedule_backup($id);
         }
         delete_path($this->dump_file);
         $this->log('NOTICE', sprintf(__('Successfully archived %1$s files in %2$s seconds. Archive file size is %3$s.', $this->text_domain), number_format_i18n($zip['count']), number_format_i18n($zip['time'], 3), size_format(filesize($file_path), 2)));
         $this->options['backup_list'][$id]['file_path'] = $file_path;
     }
     if ($this->options['drive_number'] > 0 && $this->goauth->is_authorized()) {
         if (is_wp_error($e = $this->need_gdocs())) {
             $this->log_wp_error($e);
             $this->reschedule_backup($id);
         }
         if (empty($this->options['backup_list'][$id]['location'])) {
             $this->log('NOTICE', __("Attempting to upload archive to Google Drive.", $this->text_domain));
             $location = $this->gdocs->prepare_upload($this->options['backup_list'][$id]['file_path'], $this->options['backup_list'][$id]['title'], $this->options['drive_folder']);
         } else {
             $this->log('NOTICE', __('Attempting to resume upload.', $this->text_domain));
             $location = $this->gdocs->resume_upload($this->options['backup_list'][$id]['file_path'], $this->options['backup_list'][$id]['location']);
         }
         if (is_wp_error($location)) {
             $this->log_wp_error($location);
             $this->reschedule_backup($id);
         }
         if (is_string($location)) {
             $res = $location;
             $this->log('NOTICE', sprintf(__("Uploading file with title '%s'.", $this->text_domain), esc_html($this->options['backup_list'][$id]['title'])));
             $d = 0;
             echo '<div id="progress">';
             do {
                 $this->options['backup_list'][$id]['location'] = $res;
                 $res = $this->gdocs->upload_chunk();
                 $p = $this->gdocs->get_upload_percentage();
                 if ($p - $d >= 1) {
                     $b = intval($p - $d);
                     echo '<span style="width:' . $b . '%"></span>';
                     $d += $b;
                 }
                 $this->options['backup_list'][$id]['percentage'] = $p;
                 $this->options['backup_list'][$id]['speed'] = $this->gdocs->get_upload_speed();
             } while (is_string($res));
             echo '</div>';
             if (is_wp_error($res)) {
                 $this->log_wp_error($res);
                 $this->reschedule_backup($id);
             }
             $this->log('NOTICE', sprintf(__('The file was successfully uploaded to Google Drive in %1$s seconds at an upload speed of %2$s/s.', $this->text_domain), number_format_i18n($this->gdocs->time_taken(), 3), size_format($this->gdocs->get_upload_speed())));
             unset($this->options['backup_list'][$id]['location'], $this->options['backup_list'][$id]['attempt']);
         } elseif (true === $location) {
             $this->log('WARNING', sprintf(__("The file '%s' is already uploaded.", $this->text_domain), esc_html($this->options['backup_list'][$id]['file_path'])));
         }
         $this->options['backup_list'][$id]['drive_id'] = $this->gdocs->get_file_id();
         unset($this->options['backup_list'][$id]['percentage'], $this->options['backup_list'][$id]['speed']);
         $this->update_quota();
         if (empty($this->options['user_info'])) {
             $this->set_user_info();
         }
     }
     $this->options['backup_list'][$id]['status'] = 1;
     $this->purge_backups();
     $this->log('NOTICE', sprintf(__('Backup process completed in %1$s seconds.' . ' Initial PHP memory usage was %2$s and the backup process used another %3$s of RAM.', $this->text_domain), number_format_i18n(microtime(true) - $this->time, 3), size_format($used_memory, 2), size_format(memory_get_peak_usage(true) - $used_memory, 2)));
 }
Example #4
0
function write_log()
{
    global $backup_filename, $date_stamp, $send_log, $label, $full_path;
    $log_file = $full_path . '/backup_log.txt';
    if (!($handle = fopen($log_file, 'a+'))) {
        exit;
    }
    if (is_writable($log_file)) {
        echo '<h2>Mysqldump...</h2>';
        $dumped = db_dump();
        echo '<h2>Sending db...</h2>';
        $log_content = "\n" . $date_stamp . "\t\t\t" . $dumped . "\t\t\t" . send_attachment($backup_filename);
        echo '<h2>Writing log...</h2>';
        $log_header = '';
        if (filesize($log_file) == '0') {
            $log_header .= $label . "\n\n";
            $log_header .= 'Backup log' . "\n";
            $log_header .= '----------------------------------------------' . "\n";
            $log_header .= 'DATESTAMP:					DUMPED		MAILED' . "\n";
            $log_header .= '----------------------------------------------';
            if (fwrite($handle, $log_header) === false) {
                exit;
            }
        }
        echo 'Log header written: ';
        if (fwrite($handle, $log_header) === false) {
            echo 'no<br />' . "\n";
            exit;
        } else {
            echo 'yes<br />' . "\n";
        }
        echo 'Log status written: ';
        if (fwrite($handle, $log_content) === false) {
            echo 'no<br />' . "\n";
            exit;
        } else {
            echo 'yes<br />' . "\n";
        }
    }
    fclose($handle);
    if ($send_log) {
        echo '<h2>Sending log...</h2>';
        send_attachment($log_file, false);
    }
}