Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Member
    Join Date
    Aug 2013
    Posts
    89
    Member #
    37057

    Backup script failing to backup with accuracy

    Hi, can someone help with the following code. It should backup my entire web host and all directories including all files within those directories, it's not ?

    Code:
     <?php
    
    // ZIP Everything into one zip file
    
    // Create a new directory called "mybackup".
    // It's important to use that name because you don't want the
    // backup script to backup previous backups.  It will ignore
    // the directory where your backup zipped files are located.
    
    // Call this script something like "backup123.php" and put it into your main website directory.
    // Make this script name something that nobody can easily figure out.  Don't call it "backup.php"
    
    $file="backup".time().".zip";
    if(Zip('./', './mybackup/'.$file)===TRUE){
    echo "Zip Complete";
    }
    else{
    echo "Did not zip";
    }
    
    function Zip($source, $destination){
        if (!extension_loaded('zip') || !file_exists($source)) {
            return false;
        }
    
        $zip = new ZipArchive();
        if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
            return false;
        }
    
        $source = str_replace('\\', '/', realpath($source));
    
        if (is_dir($source) === true){
            $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
    
            foreach ($files as $file){
                $file = str_replace('\\', '/', $file);
    
                // Ignore "." and ".." folders
                if( in_array(substr($file, strrpos($file, '/')+1), array('.', '..','mybackup')) )
                    continue;
    
                $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();
    }
    ?>

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,686
    Member #
    5580
    Liked
    716 times
    Christopher ...

    I have to say again that this one still has me totally stumped. I don't see any reason why it shouldn't work. Hopefully someone else has some answers to this.

    I still think that it isn't necessary to back everything up, merely the database (MySQL), uploaded images, and your theme directory. The rest of your website not involving WordPress ... just do an FTP download once in a while. It's not like it changes very much does it?


  4. #3
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,686
    Member #
    5580
    Liked
    716 times
    How about this ...

    Let's assume when the executing script comes to itself, it stops.
    So put the backup script into the 'mybackup' directory and execute it from there.
    'mybackup' is not archived ... that is the directory where the zipped file will be placed.

    In order to run the backup PHP script in the 'mybackup' directory,

    I think you'll need to change this line:

    if(Zip('./', './mybackup/'.$file)===TRUE){

    to this:

    if(Zip('../', $file)===TRUE){

    It will have to go back one directory to access the main directory ../ instead of ./
    ... and the backup script will already be in the 'mybackup' directory.

    See what happens now.
    Last edited by mlseim; Nov 18th, 2013 at 08:57 AM.


  5. #4
    Member
    Join Date
    Aug 2013
    Posts
    89
    Member #
    37057
    Script Error Occur I sent the list of errors.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:30 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com