Schedule backups with ISPConfig?

Discussion in 'General' started by hmfireball, Jun 3, 2008.

  1. hmfireball

    hmfireball New Member

    That depends on the FTP client you use and what you want to do.
    In a web browser, typing ftp://(server.ip)/folder/folder/ should list the content of folder/folder/
    Is this what you wanted to know?

    Henri
     
  2. gjcomputer

    gjcomputer New Member



    henri, you have a pm :)
     
  3. hmfireball

    hmfireball New Member

    You're right GJ, I forgot to explain something about the script :)

    By default, the script will create a folder for each web (web1, web2, web3, etc.) in the root folder of your FTP account

    This is suitable for my case but it might not be for yours.

    Here's a new version that allows you to define the path to the folder where you
    want the web folders to be created:

    PHP:
    // HENRI Version 3
    set_time_limit(0);

    include(
    "/root/ispconfig/scripts/lib/config.inc.php");
    include(
    "/root/ispconfig/scripts/lib/server.inc.php");

    if(
    $go_info["server"]["do_automated_backups"] != 1) die();

    // Erstelle Namen für Backup Datei
    $backup_file_name "backup_".date("Y_m_d",time()).".zip";

    // HENRI
    define('FTP_SERVER''xxxxxx');
    define('FTP_USER_NAME''xxxxxxx');
    define('FTP_USER_PASS''xxxxxxxxx');
    define('FTP_PATH'''); // the path to the folder where backup files will be stored. e.g. '/my/folder' (no slash at the end)
                            // leave it empty to store backup files in the root folder of the FTP account
    define('FTP_DAYS'20); // the script will keep FTP backups this number of days. Min value is 1.

    // set old_backup_file_name
    $old_time mktime(000date('m'), date('d') - FTP_DAYSdate('Y'));
    $old_backup_file_name 'backup_'.date('Y_m_d'$old_time).'.zip';
    //~HENRI


    // [...]


                    // Delete temp file
                    
    exec("rm -rf $tmp_dir");
                    
                    
    // HENRI Send file to FTP server
                    
    send_backup($web_id$backup_dir);
                    
    //~HENRI

    }

    // All web site
    $webs $mod->db->queryAllRecords("SELECT * FROM isp_isp_web");
    if(!empty(
    $webs)){
      foreach(
    $webs as $web){
        
    do_backup($web['doc_id']);
      }
    }

    // HENRI
    function send_backup($web_id$backup_dir) {
        global 
    $backup_file_name$old_backup_file_name;
        
        
    // Connect and login to FTP server
        
    $conn_id = @ftp_connect(FTP_SERVER);
        
    $login_result = @ftp_login($conn_idFTP_USER_NAMEFTP_USER_PASS);
        if (!
    $conn_id || !$login_result) {
            echo 
    "FTP connection failed for ".FTP_USER_NAME."!\n";
            return 
    false;
        }
        else {
            echo 
    FTP_USER_NAME." connected\n";
        }
        
        
    // Create web_dir if necessary
        
    $web_dir FTP_PATH.'/web'.$web_id;
        if (@
    ftp_mkdir($conn_id$web_dir)) {
            echo 
    "Created $web_dir\n";
        }
        
        
    // Upload backup
        
    $destination_file $web_dir.'/'.$backup_file_name;
        
    $source_file $backup_dir.'/'.$backup_file_name;
        
    $uploaded = @ftp_put($conn_id$destination_file$source_fileFTP_BINARY);
        
        
    // Display result
        
    if (!$uploaded) {
            echo 
    "Failed sending $destination_file\n";
        }
        else {
            echo 
    "Successed sending $destination_file\n";
            
            
    // Remove old backup
            
    $destination_file $web_dir.'/'.$old_backup_file_name;
            if (@
    ftp_delete($conn_id$destination_file)) {
                echo 
    "Removed old backup: $destination_file\n";
            }
        }
        
        
    // Close FTP connection
        
    @ftp_close($conn_id);
        
        return 
    $uploaded;
    }
    //~HENRI



    In your case, you should write :

    PHP:
    define('FTP_SERVER''XXX.XXX.XXX.XXX'); // replace by the real IP
    define('FTP_USER_NAME''xxxxxxx');
    define('FTP_USER_PASS''xxxxxxxxx');
    define('FTP_PATH''/array1/web'); // no slash at the end


    It should work :)

    Henri
     
  4. gjcomputer

    gjcomputer New Member

    it sure did! thanks Henri, you helped me to do exactly what i have been trying to accomplish for at least a year. your modification should make it into ispconfig3! at the very least, you should be promoted to developer, you know what your doing. thanks again:)
     
  5. hmfireball

    hmfireball New Member

    Very happy it was useful to you too :)
    Maybe this feature is already in ISPConfig3.
    Does somebody know?

    Henri
     

Share This Page