Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > ISPConfig 2 > General

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #11  
Old 10th June 2008, 19:25
gjcomputer gjcomputer is offline
Member
 
Join Date: Jan 2006
Location: missouri, USA
Posts: 91
Thanks: 15
Thanked 2 Times in 2 Posts
Default

Quote:
Originally Posted by till View Post
This script is not made to run backups on a FTP server. It might be easoier if you write a custom shell script that simply makes a tar.gz file of the /var/www directory (or the place were your webs are stored) and then copy the tar.gz file to the ftp server.
that would work. do you have any tips on doing this?
__________________
6r36.com
Reply With Quote
Sponsored Links
  #12  
Old 11th June 2008, 12:38
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,741 Times in 2,575 Posts
Default

You can use the tutorial I posted earlier in this thread.
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #13  
Old 18th June 2008, 18:50
hmfireball hmfireball is offline
Junior Member
 
Join Date: May 2008
Location: Nancy, France
Posts: 27
Thanks: 0
Thanked 4 Times in 3 Posts
Default My code to automate sending backups to FTP Server

This the first version of the code I wrote to send backups to an FTP Server.
It's really simple!
You just have to add the codes between // HENRI and //~HENRI to the right places (near line 133) of the /root/ispconfig/scripts/shell/backup.php script.
Beware that this script will send a new backup everyday and thus fill the FTP Server (it's a first version)!
Henri


PHP Code:
// [...]

                // Delete temp file
                
exec("rm -rf $tmp_dir");
                
                
// HENRI Send file to FTP server
                
send_backup($web_id$backup_dir$backup_file_name);
                
//~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$backup_file_name) {

    
// Replace by your own parameters
    
$ftp_server 'XXXXXXXX';
    
$ftp_user_name 'XXXXXXXX';
    
$ftp_user_pass 'XXXXXXXXX';
    
    
// Connect and login to FTP server
    
$conn_id = @ftp_connect($ftp_server);
    
$login_result = @ftp_login($conn_id$ftp_user_name$ftp_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 '/web'.$web_id;
    if (@
ftp_mkdir($conn_id$web_dir)) {
        echo 
"Created $web_dir\n";
    }
    
    
$destination_file $web_dir.'/'.$backup_file_name;
    
$source_file $backup_dir.'/'.$backup_file_name;
    
    
// Upload backup
    
$upload = @ftp_put($conn_id$destination_file$source_fileFTP_BINARY);
    
    
// Display result
    
if (!$upload) {
        echo 
"Failed sending $destination_file\n";
    }
    else {
        echo 
"Successed sending $destination_file\n";
    }
    
    
// Close FTP connection
    
@ftp_close($conn_id);
    
    return 
$upload;
}
//~HENRI 

Last edited by hmfireball; 18th June 2008 at 18:55.
Reply With Quote
The Following User Says Thank You to hmfireball For This Useful Post:
gjcomputer (18th June 2008)
  #14  
Old 18th June 2008, 19:56
gjcomputer gjcomputer is offline
Member
 
Join Date: Jan 2006
Location: missouri, USA
Posts: 91
Thanks: 15
Thanked 2 Times in 2 Posts
Default

thanks bud im gonna give this a try. maybe 2nd version can overwrite after a set amount of time?

Quote:
Originally Posted by hmfireball View Post
This the first version of the code I wrote to send backups to an FTP Server.
It's really simple!
You just have to add the codes between // HENRI and //~HENRI to the right places (near line 133) of the /root/ispconfig/scripts/shell/backup.php script.
Beware that this script will send a new backup everyday and thus fill the FTP Server (it's a first version)!
Henri


PHP Code:
// [...]

                // Delete temp file
                
exec("rm -rf $tmp_dir");
                
                
// HENRI Send file to FTP server
                
send_backup($web_id$backup_dir$backup_file_name);
                
//~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$backup_file_name) {

    
// Replace by your own parameters
    
$ftp_server 'XXXXXXXX';
    
$ftp_user_name 'XXXXXXXX';
    
$ftp_user_pass 'XXXXXXXXX';
    
    
// Connect and login to FTP server
    
$conn_id = @ftp_connect($ftp_server);
    
$login_result = @ftp_login($conn_id$ftp_user_name$ftp_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 '/web'.$web_id;
    if (@
ftp_mkdir($conn_id$web_dir)) {
        echo 
"Created $web_dir\n";
    }
    
    
$destination_file $web_dir.'/'.$backup_file_name;
    
$source_file $backup_dir.'/'.$backup_file_name;
    
    
// Upload backup
    
$upload = @ftp_put($conn_id$destination_file$source_fileFTP_BINARY);
    
    
// Display result
    
if (!$upload) {
        echo 
"Failed sending $destination_file\n";
    }
    else {
        echo 
"Successed sending $destination_file\n";
    }
    
    
// Close FTP connection
    
@ftp_close($conn_id);
    
    return 
$upload;
}
//~HENRI 
__________________
6r36.com
Reply With Quote
  #15  
Old 18th June 2008, 22:14
vaio1 vaio1 is offline
Senior Member
 
Join Date: Jul 2007
Location: Italy
Posts: 664
Thanks: 77
Thanked 12 Times in 7 Posts
Default

Hi, I suggest my Backup system for ISPConfig!
http://www.howtoforge.com/forums/showthread.php?t=15337

Regards,
mturillo
Reply With Quote
  #16  
Old 19th June 2008, 00:31
Jorem Jorem is offline
Senior Member
 
Join Date: Oct 2005
Posts: 139
Thanks: 5
Thanked 4 Times in 4 Posts
Default

I use the filesystem backup function in Webmin.

Very easy. You can shedule backups. Use SSH or FTP server. And you get an email on succes.

Last edited by Jorem; 19th June 2008 at 00:33.
Reply With Quote
  #17  
Old 19th June 2008, 18:06
hmfireball hmfireball is offline
Junior Member
 
Join Date: May 2008
Location: Nancy, France
Posts: 27
Thanks: 0
Thanked 4 Times in 3 Posts
Default My code to automate sending backups to FTP Server (version 2)

This version removes old backup from FTP server after a given number of days.
Add the codes between // HENRI and //~HENRI to the right places in the /root/ispconfig/scripts/shell/backup.php script.

PHP Code:
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
// Replace with your own parameters
define('FTP_SERVER''XXXXXXX');
define('FTP_USER_NAME''XXXXXXXXX');
define('FTP_USER_PASS''XXXXXXXXX');
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 '/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 


Henri
http://www.absyx.fr
Reply With Quote
  #18  
Old 20th June 2008, 00:01
gjcomputer gjcomputer is offline
Member
 
Join Date: Jan 2006
Location: missouri, USA
Posts: 91
Thanks: 15
Thanked 2 Times in 2 Posts
Default

thanks once again, this one is easier to follow. what is the best way to test and make sure this works? i tried running the php manually, and it doesnt do anything
__________________
6r36.com
Reply With Quote
  #19  
Old 20th June 2008, 09:30
hmfireball hmfireball is offline
Junior Member
 
Join Date: May 2008
Location: Nancy, France
Posts: 27
Thanks: 0
Thanked 4 Times in 3 Posts
Default

Before you run the script, you must enable automated backup in ISPConfig's config file.

In /home/admispconfig/ispconfig/lib/config.inc.php, find the line:
PHP Code:
$go_info["server"]["do_automated_backups"] = 0// 0 = no, 1 = yes; PLEASE NOTE: automated backups might fill up your HDD fast! 


and set it to 1:
PHP Code:
$go_info["server"]["do_automated_backups"] = 1// 0 = no, 1 = yes; PLEASE NOTE: automated backups might fill up your HDD fast! 


Save and restart ISPConfig server (not sure it's needed though):
Code:
/etc/init.d/ispconfig_server restart
Then try to run the script manually:
Code:
/root/ispconfig/php/php /root/ispconfig/scripts/shell/backup.php
Backup should start and you should see logs about backup files being sent to the FTP Server.
Once it's done, connect to the FTP Server and check if the files are where they're expected to be

Henri
http://www.absyx.fr

Last edited by hmfireball; 20th June 2008 at 09:57.
Reply With Quote
  #20  
Old 20th June 2008, 15:42
gjcomputer gjcomputer is offline
Member
 
Join Date: Jan 2006
Location: missouri, USA
Posts: 91
Thanks: 15
Thanked 2 Times in 2 Posts
 
Default

Quote:
Originally Posted by hmfireball View Post
Save and restart ISPConfig server (not sure it's needed though):
Code:
/etc/init.d/ispconfig_server restart
Then try to run the script manually:
Code:
/root/ispconfig/php/php /root/ispconfig/scripts/shell/backup.php
Backup should start and you should see logs about backup files being sent to the FTP Server.
Once it's done, connect to the FTP Server and check if the files are where they're expected to be

Henri
http://www.absyx.fr
got it, thanks. this script looks like what i wanted too.

under ftp server, the correct syntax is
Code:
define('FTP_SERVER', '192.168.1.105/array1/web/');
correct?
__________________
6r36.com

Last edited by gjcomputer; 20th June 2008 at 16:14.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
I love ISPConfig rafael-ec General 0 9th August 2007 18:09
Ispconfig update problems from 2.4 to 2.6 adrenalinic Installation/Configuration 23 7th September 2006 12:58
4 questions about ispconfig and domains, please help! dimas Installation/Configuration 7 1st August 2006 11:55
Migrating from Virtualmin to ISPConfig xare Installation/Configuration 3 16th July 2006 12:58
ISPConfig Backups SleeperZ Feature Requests 0 9th November 2005 09:36


All times are GMT +2. The time now is 07:49.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.