Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2004

    Question Unanswered: Help me find a way please

    I'm hoping someone here can help me find a way to do something. I use a popular eCommerce software program written in PHP that has a Database backup built into it.

    What I am looking for is some code I can add to it that will also allow me to backup my entire website and compress it into a zip file, including the the DB.

    Since the DB backup already gives the choice to save to a file or download it to your PC I think it would only require a few lines of code added, but not being a code writer I have no idea where to start.

    Thank in advance.

    Bob G.

  2. #2
    Join Date
    Mar 2004

    I have a partial answer

    I found this piece of code in another forum that does a great job of backing up my entire website, and if I do a DB backup first it's included with the backup.

    All I need now is to find a way that when this script ends, it will display all the files in the system_backup directory so they can be downloaded to the PC.

    Here is the script:

    $Id: sysbackup.php 2005/01/02 01:53:52 hpdl Exp $

    Grasshoppers Gifts and Novelties

    Copyright (c) 2005 Grasshoppers Gifts and Novelties

    Released under the GNU General Public License
    $backupdate = date("Ymd_H-i-s");
    //Backup date variable. Replace "Ymd" with
    //"Ymd_H-i-s" to include the time.

    $backupdir = "/path/to/website/";
    //Change to the absolute path to your website

    $files = "*";
    //What file to backup? Use a * to backup all the files
    //inside the folder entered above.

    $backupto = "/path/to/website/admin/system_backup/";
    //Change to the absolute path to your /admin/system_backup directory

    $fileprefix = "bak";
    //This is the prefix that will be added before the date:
    //The underscore _ is added automatically

    $tararg = "-cf";
    //Here goes the tar arguments. I recommend -cf.
    //c is for compressing. f is for outputting
    //a file.

    $bz2arg = "-z9";
    //Here goes the bunzip2 arguments. I recommend -z9.
    //z is for creating a archive
    //and 9 is for max compression. z is always needed

    //Call the function

    function backupsus() {
    global $backupdate,$backupdir,$backupto,
    $backupsuscmd = "cd $backupdir;
    tar $tararg {$fileprefix}_{$backupdate}.tar $files;
    bunzip2 $bz2arg {$fileprefix}_{$backupdate}.tar;
    mv {$fileprefix}_{$backupdate}.tar $backupto";
    passthru ("$backupsuscmd");
    echo "Your System Backup is now complete! Remember to FTP the backup to your PC.";

    I was thinking of adding a button after the "Your Syste Back ....." that would open the directory but I'm not sure how to do it in PHP.

    Thanks in advance,

    Bob G.

  3. #3
    Join Date
    Mar 2004

    Found a way

    By adding this piece of code at the end, it now gives a list of all the files in the directory defined and allows them to be saved to the PC.

    function directory($result) {

    while ($file = readdir($handle)) {
    if ($file == "." || $file == "..") { } else { print "<a href=system_backup/$file>$file</a><br>\n"; }


    return $result;
    <b>Your System Backup is now complete! Select the backup version you want to save from the list below:</b>
    echo directory($result);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts