Browse Source

changes for better security

master
Christoph Miksche 2 years ago
parent
commit
95e1a2fb8b
3 changed files with 14 additions and 28 deletions
  1. +4
    -14
      backup.php
  2. +3
    -0
      backup/.htaccess
  3. +7
    -14
      myphp-backup/myphp-backup.php

+ 4
- 14
backup.php View File

@@ -19,7 +19,7 @@ ini_set('memory_limit', '2048M');
// Set script max execution time
set_time_limit(900);

// Database Backup Skript from https://github.com/daniloaz/myphp-backup
// Database Backup Skript from https://github.com/daniloaz/myphp-backup
require_once('myphp-backup/myphp-backup.php');

// Function to Recursively Backup Files & Folders to ZIP-File
@@ -57,23 +57,13 @@ function zipData($source, $destination) {
* Instantiate Backup_Database and perform backup
*/

if (php_sapi_name() != "cli") {
echo '<div style="font-family: monospace;">';
}

$backupDatabase = new Backup_Database(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$result = $backupDatabase->backupTables(TABLES, BACKUP_DIR) ? 'OK' : 'KO';
$backupDatabase->obfPrint('Backup result: ' . $result, 1);

if (php_sapi_name() != "cli") {
echo '</div>';
}
$backupDatabase->backupTables(TABLES, BACKUP_DIR) ? 'OK' : 'KO';

// ZIP

$bckfile = BACKUP_DIR.'/'.date('Y-m-d').'-files.tar';

//zipData('../', $bckfile);
//
$bckfile = BACKUP_DIR.'/'.date('Y-m-d').'-files.tar';

// Phar
$phar = new PharData($bckfile);


+ 3
- 0
backup/.htaccess View File

@@ -0,0 +1,3 @@
<Files "*">
Deny from all
</Files>

+ 7
- 14
myphp-backup/myphp-backup.php View File

@@ -1,4 +1,4 @@
<?php
<?php
/**
* This file contains the Backup_Database class wich performs
* a partial or complete backup of any given MySQL database
@@ -41,7 +41,7 @@ class Backup_Database {
var $conn;

/**
* Backup directory where backup files are stored
* Backup directory where backup files are stored
*/
var $backupDir;

@@ -115,8 +115,6 @@ class Backup_Database {
* Iterate tables
*/
foreach($tables as $table) {
$this->obfPrint("Backing up `".$table."` table...".str_repeat('.', 50-strlen($table)), 0, 0);

/**
* CREATE TABLE
*/
@@ -131,11 +129,11 @@ class Backup_Database {
$row = mysqli_fetch_row(mysqli_query($this->conn, 'SELECT COUNT(*) FROM `'.$table.'`'));
$numRows = $row[0];

// Split table in batches in order to not exhaust system memory
// Split table in batches in order to not exhaust system memory
$batchSize = 1000; // Number of rows per batch
$numBatches = intval($numRows / $batchSize) + 1; // Number of while-loop calls to perform
for ($b = 1; $b <= $numBatches; $b++) {
$query = 'SELECT * FROM `'.$table.'` LIMIT '.($b*$batchSize-$batchSize).','.$batchSize;
$result = mysqli_query($this->conn, $query);
$numFields = mysqli_num_fields($result);
@@ -167,8 +165,6 @@ class Backup_Database {
}

$sql.="\n\n\n";

$this->obfPrint(" OK");
}

if ($this->gzipBackupFile) {
@@ -221,8 +217,6 @@ class Backup_Database {
$source = $this->backupDir . '/' . $this->backupFile;
$dest = $source . '.gz';

$this->obfPrint('Gzipping backup file to ' . $dest . '... ', 1, 0);

$mode = 'wb' . $level;
if ($fpOut = gzopen($dest, $mode)) {
if ($fpIn = fopen($source,'rb')) {
@@ -240,8 +234,7 @@ class Backup_Database {
} else {
return false;
}
$this->obfPrint('OK');

return $dest;
}

@@ -265,7 +258,7 @@ class Backup_Database {
if ($lineBreaksBefore > 0) {
for ($i = 1; $i <= $lineBreaksBefore; $i++) {
$output .= $lineBreak;
}
}
}

$output .= $msg;
@@ -273,7 +266,7 @@ class Backup_Database {
if ($lineBreaksAfter > 0) {
for ($i = 1; $i <= $lineBreaksAfter; $i++) {
$output .= $lineBreak;
}
}
}

echo $output;


Loading…
Cancel
Save