Skip to content

Instantly share code, notes, and snippets.

@doyomay
Forked from menzerath/backup.php
Created February 18, 2021 11:32
Show Gist options
  • Select an option

  • Save doyomay/19bbcd3d8fd3cc977159ca9c64382201 to your computer and use it in GitHub Desktop.

Select an option

Save doyomay/19bbcd3d8fd3cc977159ca9c64382201 to your computer and use it in GitHub Desktop.

Revisions

  1. @menzerath menzerath revised this gist Jan 23, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion backup.php
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@

    // Make sure the script can handle large folders/files
    ini_set('max_execution_time', 600);
    ini_set('memory_limit','1024M');
    ini_set('memory_limit', '1024M');

    // Start the backup!
    zipData('/path/to/folder', '/path/to/backup.zip');
  2. @menzerath menzerath revised this gist Jan 23, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions backup.php
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    <?php
    /*
    * PHP: Recursively Backup Files & Folders to ZIP-File
    * MIT-License - Copyright (c) 2012-2017 Marvin Menzerath
    * MIT-License - 2012-2018 Marvin Menzerath
    */

    // Make sure the script can handle large folders/files
    @@ -20,7 +20,7 @@ function zipData($source, $destination) {
    if ($zip->open($destination, ZIPARCHIVE::CREATE)) {
    $source = realpath($source);
    if (is_dir($source)) {
    $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
    $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST);
    foreach ($files as $file) {
    $file = realpath($file);
    if (is_dir($file)) {
  3. @menzerath menzerath revised this gist May 23, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions backup.php
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    <?php
    /*
    * PHP: Recursively Backup Files & Folders to ZIP-File
    * (c) 2012-2014: Marvin Menzerath - http://menzerath.eu
    * MIT-License - Copyright (c) 2012-2017 Marvin Menzerath
    */

    // Make sure the script can handle large folders/files
    @@ -13,7 +13,7 @@
    echo 'Finished.';

    // Here the magic happens :)
    function zipData($folder, $zipTo) {
    function zipData($source, $destination) {
    if (extension_loaded('zip')) {
    if (file_exists($source)) {
    $zip = new ZipArchive();
  4. Marvin Menzerath revised this gist Feb 28, 2014. 1 changed file with 9 additions and 9 deletions.
    18 changes: 9 additions & 9 deletions backup.php
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    <?php
    /*
    * PHP Recursive Backup-Script to ZIP-File
    * (c) 2012-2013: Marvin Menzerath. (http://menzerath.eu)
    * PHP: Recursively Backup Files & Folders to ZIP-File
    * (c) 2012-2014: Marvin Menzerath - http://menzerath.eu
    */

    // Make sure the script can handle large folders/files
    @@ -14,22 +14,22 @@

    // Here the magic happens :)
    function zipData($folder, $zipTo) {
    if (extension_loaded('zip') === true) {
    if (file_exists($source) === true) {
    if (extension_loaded('zip')) {
    if (file_exists($source)) {
    $zip = new ZipArchive();
    if ($zip->open($destination, ZIPARCHIVE::CREATE) === true) {
    if ($zip->open($destination, ZIPARCHIVE::CREATE)) {
    $source = realpath($source);
    if (is_dir($source) === true) {
    if (is_dir($source)) {
    $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
    foreach ($files as $file) {
    $file = realpath($file);
    if (is_dir($file) === true) {
    if (is_dir($file)) {
    $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
    } else if (is_file($file) === true) {
    } else if (is_file($file)) {
    $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
    }
    }
    } else if (is_file($source) === true) {
    } else if (is_file($source)) {
    $zip->addFromString(basename($source), file_get_contents($source));
    }
    }
  5. @menzerath menzerath revised this gist May 28, 2013. 1 changed file with 24 additions and 28 deletions.
    52 changes: 24 additions & 28 deletions backup.php
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    <?php
    /*
    * PHP Recursive Backup-Script to ZIP-File
    * (c) 2012: Marvin Menzerath. (http://menzerath.eu)
    * (c) 2012-2013: Marvin Menzerath. (http://menzerath.eu)
    */

    // Make sure the script can handle large folders/files
    @@ -14,32 +14,28 @@

    // Here the magic happens :)
    function zipData($folder, $zipTo) {
    if (extension_loaded('zip') === true) {
    if (file_exists($source) === true) {
    $zip = new ZipArchive();

    if ($zip->open($destination, ZIPARCHIVE::CREATE) === true) {
    $source = realpath($source);

    if (is_dir($source) === true) {
    $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);

    foreach ($files as $file) {
    $file = realpath($file);

    if (is_dir($file) === true) {
    $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
    } else if (is_file($file) === true) {
    $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
    }
    }
    } else if (is_file($source) === true) {
    $zip->addFromString(basename($source), file_get_contents($source));
    }
    }
    return $zip->close();
    }
    }
    return false;
    if (extension_loaded('zip') === true) {
    if (file_exists($source) === true) {
    $zip = new ZipArchive();
    if ($zip->open($destination, ZIPARCHIVE::CREATE) === true) {
    $source = realpath($source);
    if (is_dir($source) === true) {
    $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
    foreach ($files as $file) {
    $file = realpath($file);
    if (is_dir($file) === true) {
    $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
    } else if (is_file($file) === true) {
    $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
    }
    }
    } else if (is_file($source) === true) {
    $zip->addFromString(basename($source), file_get_contents($source));
    }
    }
    return $zip->close();
    }
    }
    return false;
    }
    ?>
  6. @menzerath menzerath revised this gist Dec 1, 2012. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions backup.php
    Original file line number Diff line number Diff line change
    @@ -3,13 +3,14 @@
    * PHP Recursive Backup-Script to ZIP-File
    * (c) 2012: Marvin Menzerath. (http://menzerath.eu)
    */

    // Make sure the script can handle large folders/files
    ini_set('max_execution_time', 600);
    ini_set('memory_limit','1024M');

    // Start the backup!
    zipData('/path/to/folder', '/path/to/backup_'.date("d.m.Y-H.i").'.zip');
    echo date("d.m.Y-H.i").' - Abgeschlossen.';
    zipData('/path/to/folder', '/path/to/backup.zip');
    echo 'Finished.';

    // Here the magic happens :)
    function zipData($folder, $zipTo) {
  7. @invalid-email-address Anonymous created this gist Dec 1, 2012.
    44 changes: 44 additions & 0 deletions backup.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    <?php
    /*
    * PHP Recursive Backup-Script to ZIP-File
    * (c) 2012: Marvin Menzerath. (http://menzerath.eu)
    */
    // Make sure the script can handle large folders/files
    ini_set('max_execution_time', 600);
    ini_set('memory_limit','1024M');

    // Start the backup!
    zipData('/path/to/folder', '/path/to/backup_'.date("d.m.Y-H.i").'.zip');
    echo date("d.m.Y-H.i").' - Abgeschlossen.';

    // Here the magic happens :)
    function zipData($folder, $zipTo) {
    if (extension_loaded('zip') === true) {
    if (file_exists($source) === true) {
    $zip = new ZipArchive();

    if ($zip->open($destination, ZIPARCHIVE::CREATE) === true) {
    $source = realpath($source);

    if (is_dir($source) === true) {
    $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);

    foreach ($files as $file) {
    $file = realpath($file);

    if (is_dir($file) === true) {
    $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
    } else if (is_file($file) === true) {
    $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
    }
    }
    } else if (is_file($source) === true) {
    $zip->addFromString(basename($source), file_get_contents($source));
    }
    }
    return $zip->close();
    }
    }
    return false;
    }
    ?>