Exemplo n.º 1
0
$versionCheck = new version();
$version_info = $versionCheck->check($phpMySQLAutoBackup_version);
$backup_info = "\n" . $version_info . "\n\n";
$backup_info .= $backup_type;
$backup_info .= $recordBackup->get();
// zip the backup and email it
$backup_file_name = 'mysql_' . $db . strftime("_%d_%b_%Y_time_%H_%M_%S.sql", time()) . '.gz';
$dump_buffer = gzencode($buffer);
if ($save_backup_zip_file_to_server) {
    write_backup($dump_buffer, $backup_file_name);
}
//FTP backup file to remote server
if (isset($ftp_username)) {
    //write the backup file to local server ready for transfer if not already done so
    if (!$save_backup_zip_file_to_server) {
        write_backup($dump_buffer, $backup_file_name);
    }
    $transfer_backup = new transfer_backup();
    $errors .= $transfer_backup->transfer_data($ftp_username, $ftp_password, $ftp_server, $ftp_path, $backup_file_name);
    if (!$save_backup_zip_file_to_server) {
        unlink(LOCATION . "../backups/" . $backup_file_name);
    }
}
if (!session_id()) {
    session_start();
}
if (isset($_SESSION['pmab_mysql_errors'])) {
    $errors .= $_SESSION['pmab_mysql_errors'];
}
if ($send_email_backup) {
    xmail($to_emailaddress, $from_emailaddress, "phpMySQLAutoBackup: {$backup_file_name}", $dump_buffer, $backup_file_name, $backup_type, $phpMySQLAutoBackup_version);
Exemplo n.º 2
0
function create_backup($file)
{
    $line_count = 0;
    $tables = mysql_list_tables(DB_NAME);
    $sql_string = NULL;
    while ($table = mysql_fetch_array($tables)) {
        $table_name = $table[0];
        $sql_string = "\nTRUNCATE {$table_name};\n";
        $table_query = mysql_query("SELECT * FROM `{$table_name}`");
        $num_fields = mysql_num_fields($table_query);
        while ($fetch_row = mysql_fetch_array($table_query)) {
            $sql_string .= "INSERT INTO {$table_name} VALUES(";
            $first = TRUE;
            for ($field_count = 1; $field_count <= $num_fields; $field_count++) {
                if (TRUE == $first) {
                    $sql_string .= "'" . mysql_real_escape_string($fetch_row[$field_count - 1]) . "'";
                    $first = FALSE;
                } else {
                    $sql_string .= ", '" . mysql_real_escape_string($fetch_row[$field_count - 1]) . "'";
                }
            }
            $sql_string .= ");";
            if ($sql_string != "") {
                $line_count = write_backup($file, $sql_string, $line_count);
            }
            $sql_string = NULL;
        }
    }
    return $line_count;
}