Enhance the backup function of Trixbox

This page has been viewed 25978 times since being created on Sun 13 of May, 2007 (05:41 UTC)


If you have the same concern as me, that in case of the local disk crashed, you may have lost the all data within Trixbox, you have even configured the backup function for Trixbox, this article may be a good solution.

I wrote a script in perl, which let you perform the Trixbox backup in addition to storing in the local disk and also sending them to a specificed email address.

So you will have two backups for Trixbox on different location, one is in local disk, another one is in your mail-box. In my case, I prefer google mail-box, which has a very large available space and friendly user interface.

Step 1: Install a perl module 'perl-MIME-Lite' if it is not yet installed within system.

Login Trixbox with putty and then issue this command, check that whether the perl module 'perl-MIME-Lite' have existed.

$ rpm -qa | grep -i perl-MIME-Lite

Download the package and install it, issue these commands with putty.

$ su - (here will prompt the root's password)
$ wget ftp://ftp.pbone.net/mirror/atrpms.net/el4-i386/atrpms/stable/perl-MIME-Lite-3.01-5.el4.at.noarch.rpm
$ rpm -Uvh perl-MIME-Lite-3.01-5.el4.at.noarch.rpm

Have completed the installation.

Step 2: Edit the file '/var/lib/asterisk/bin/ampbackup.pl', completed these lines:

2.1)

find these lines like this: (around line 188)
if ( $ftpbackup ne "YES" ) {
exit
}


replace them with these lines like this:
if ( $ftpbackup eq "YES" ) {


2.2)

find this line like this: (around line )
exit 0;


replace it with these lines like this:
}
  1. exit 0;


2.3)

add the following scripts at the bottom.

 ##########################################################################
 #                                                                        #
 # -Backup your Trixbox with email                                        #
 #                                                                        #
 # written by alang 2007,3,31                                             #
 # email me to alang~np~[dot]~/np~hsu~np~[at]~/np~gmail~np~[dot]~/np~com                             #
 # visit my blog http://itblog.blogdns.net/                               #
 #                                                                        #
 # -Note: This script will need to install the perl module perl-MIME-Lite #
 #       on your system, if it doesn't exist.                             #
 #       Issue this command,check whether the module exist in system.     #
 #       rpm -qa | grep -i perl-MIME-Lite                                 #
 #                                                                        #
 # -Usage: Adjust the argument as per your requirement, just like the     #
 #         following.                                                     #
 #       $emailbackup, fill in 'YES' to enable this function, or fill in  #
 #       'NO' to disable it.                                              #
 #       $SenderName, fill in your name, or whatever.                     #
 #       $WebsiteName, fill in your web-site name, or whatever.           #
 #       $from_address, fill in the sender's email address.               #
 #       $to_address, fill in recipient's email address, which will       #
 #       recieve the backup file.                                         #
 #       $subject, fill in the subject of the mail.                       #
 #                                                                        #
 #       Finally, hoping you like this script, and have fun with Trixbox. #
 ##########################################################################


 use MIME::Lite;

 ################### BEGIN OF CONFIGURATION ####################
 $emailbackup = 'YES';
 $SenderName = 'Administrator-YourName';
 $WebsiteName = 'My IP PBX-Asterisk';
 $from_address = 'root@asterisk1.local';
 $to_address = 'your@email.address';
 $subject = 'MyPBX Backup Process Reporting! from ['.$WebsiteName.']';
 ################### END OF CONFIGURATION ####################

 if ( $emailbackup ne "YES" ){
         exit;
 }

 $recommended_filename_1 = "$Stamp.tar.gz";
 $attachfile = "/var/lib/asterisk/backups/$Backup_Name/$Stamp.tar.gz";
 if ( -f $attachfile )
 {

 $msg = MIME::Lite->new(
    From => $SenderName.' <'.$from_address.'>',
    To => $to_address,
    Subject => $subject,
    Type => 'text/plain',
    Data => "#############[ Please don't reply this email ]############# \n\n"
        ."Hi, ".$SenderName."\n\n"
        ."Your web(".$WebsiteName.") has completed backup as the attached file. \n"
        ."The detailed information: \n"
        ."Backup job name = $Backup_Name \n"
        ."Backup file name = $Stamp.tar.gz \n"
        ."Backup time = $mon $mday, $year at $hour:$min:$sec \n\n"
        ."Please save as it and in good keeping.")
    or die "Error creating MIME body: $!\n";

 # Attach the tar file
 $msg->attach(
    Type=>'application/x-tar',
    Path =>$attachfile,
    Filename =>$recommended_filename_1)
    or die "Error attaching tar  $!\n";

 ### Send in the "best" way (the default is to use "sendmail"):
 $msg->send();
 }

 exit 0;
 # EOF



2.4)

Adjust the argument as per your requirement, just like the following.

$emailbackup - fill in 'YES' to enable this function, or fill in 'NO' to disable it.
$SenderName - fill in your name, or whatever.
$WebsiteName - fill in your web-site name, or whatever.
$from_address - fill in the sender's email address.
$to_address - fill in recipient's email address, which will recieve the backup file.
$subject - fill in the subject of the mail.

Save it and quit.

Step 3: Configuring the backup schedule with FreePBX.

From Freepbx choose Tools -> Backup & Restore.
Next select Add Backup Schedule
Filling out all fields per your backup requirement, if this is the first time you schedule a backup, it is advisable to do the backup right now by selecting NOW from the Run Backup drop down selection box.

Step 4: Finished

Check out your mail box, you should got a mail containing the attachment to Trixbox backup.
Finally, hope you like this scipt, and have fun with Trixbox.

This page has been viewed 25978 times since being created on Sun 13 of May, 2007 (05:41 UTC)


If you have the same concern as me, that in case of the local disk crashed, you may have lost the all data within Trixbox, you have even configured the backup function for Trixbox, this article may be a good solution.

I wrote a script in perl, which let you perform the Trixbox backup in addition to storing in the local disk and also sending them to a specificed email address.

So you will have two backups for Trixbox on different location, one is in local disk, another one is in your mail-box. In my case, I prefer google mail-box, which has a very large available space and friendly user interface.

Step 1: Install a perl module 'perl-MIME-Lite' if it is not yet installed within system.

Login Trixbox with putty and then issue this command, check that whether the perl module 'perl-MIME-Lite' have existed.

$ rpm -qa | grep -i perl-MIME-Lite

Download the package and install it, issue these commands with putty.

$ su - (here will prompt the root's password)
$ wget ftp://ftp.pbone.net/mirror/atrpms.net/el4-i386/atrpms/stable/perl-MIME-Lite-3.01-5.el4.at.noarch.rpm
$ rpm -Uvh perl-MIME-Lite-3.01-5.el4.at.noarch.rpm

Have completed the installation.

Step 2: Edit the file '/var/lib/asterisk/bin/ampbackup.pl', completed these lines:

2.1)

find these lines like this: (around line 188)
if ( $ftpbackup ne "YES" ) {
exit
}


replace them with these lines like this:
if ( $ftpbackup eq "YES" ) {


2.2)

find this line like this: (around line )
exit 0;


replace it with these lines like this:
}
  1. exit 0;


2.3)

add the following scripts at the bottom.

 ##########################################################################
 #                                                                        #
 # -Backup your Trixbox with email                                        #
 #                                                                        #
 # written by alang 2007,3,31                                             #
 # email me to alang~np~[dot]~/np~hsu~np~[at]~/np~gmail~np~[dot]~/np~com                             #
 # visit my blog http://itblog.blogdns.net/                               #
 #                                                                        #
 # -Note: This script will need to install the perl module perl-MIME-Lite #
 #       on your system, if it doesn't exist.                             #
 #       Issue this command,check whether the module exist in system.     #
 #       rpm -qa | grep -i perl-MIME-Lite                                 #
 #                                                                        #
 # -Usage: Adjust the argument as per your requirement, just like the     #
 #         following.                                                     #
 #       $emailbackup, fill in 'YES' to enable this function, or fill in  #
 #       'NO' to disable it.                                              #
 #       $SenderName, fill in your name, or whatever.                     #
 #       $WebsiteName, fill in your web-site name, or whatever.           #
 #       $from_address, fill in the sender's email address.               #
 #       $to_address, fill in recipient's email address, which will       #
 #       recieve the backup file.                                         #
 #       $subject, fill in the subject of the mail.                       #
 #                                                                        #
 #       Finally, hoping you like this script, and have fun with Trixbox. #
 ##########################################################################


 use MIME::Lite;

 ################### BEGIN OF CONFIGURATION ####################
 $emailbackup = 'YES';
 $SenderName = 'Administrator-YourName';
 $WebsiteName = 'My IP PBX-Asterisk';
 $from_address = 'root@asterisk1.local';
 $to_address = 'your@email.address';
 $subject = 'MyPBX Backup Process Reporting! from ['.$WebsiteName.']';
 ################### END OF CONFIGURATION ####################

 if ( $emailbackup ne "YES" ){
         exit;
 }

 $recommended_filename_1 = "$Stamp.tar.gz";
 $attachfile = "/var/lib/asterisk/backups/$Backup_Name/$Stamp.tar.gz";
 if ( -f $attachfile )
 {

 $msg = MIME::Lite->new(
    From => $SenderName.' <'.$from_address.'>',
    To => $to_address,
    Subject => $subject,
    Type => 'text/plain',
    Data => "#############[ Please don't reply this email ]############# \n\n"
        ."Hi, ".$SenderName."\n\n"
        ."Your web(".$WebsiteName.") has completed backup as the attached file. \n"
        ."The detailed information: \n"
        ."Backup job name = $Backup_Name \n"
        ."Backup file name = $Stamp.tar.gz \n"
        ."Backup time = $mon $mday, $year at $hour:$min:$sec \n\n"
        ."Please save as it and in good keeping.")
    or die "Error creating MIME body: $!\n";

 # Attach the tar file
 $msg->attach(
    Type=>'application/x-tar',
    Path =>$attachfile,
    Filename =>$recommended_filename_1)
    or die "Error attaching tar  $!\n";

 ### Send in the "best" way (the default is to use "sendmail"):
 $msg->send();
 }

 exit 0;
 # EOF



2.4)

Adjust the argument as per your requirement, just like the following.

$emailbackup - fill in 'YES' to enable this function, or fill in 'NO' to disable it.
$SenderName - fill in your name, or whatever.
$WebsiteName - fill in your web-site name, or whatever.
$from_address - fill in the sender's email address.
$to_address - fill in recipient's email address, which will recieve the backup file.
$subject - fill in the subject of the mail.

Save it and quit.

Step 3: Configuring the backup schedule with FreePBX.

From Freepbx choose Tools -> Backup & Restore.
Next select Add Backup Schedule
Filling out all fields per your backup requirement, if this is the first time you schedule a backup, it is advisable to do the backup right now by selecting NOW from the Run Backup drop down selection box.

Step 4: Finished

Check out your mail box, you should got a mail containing the attachment to Trixbox backup.
Finally, hope you like this scipt, and have fun with Trixbox.

Created by: alang, Last modification: Thu 10 of May, 2012 (19:17 UTC) by admin
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+