Changeset 3854

Show
Ignore:
Timestamp:
03/08/07 20:58:05 (6 years ago)
Author:
p_lindheimer
Message:

add scp ability to ampbackup, similar to ftp ability. Add cofigurable provisioning file directory to be backed up specified in amportal.conf. No additions to the gui, files will be in the tarball if needed

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/branches/2.3/backup/bin/ampbackup.pl

    r3019 r3854  
    6262$User_Preferences{"AMPWEBROOT"} = "/var/www/html"; 
    6363 
     64$User_Preferences{"AMPPROVROOT"} = ""; 
     65$User_Preferences{"AMPPROVEXCLUDE"} = ""; 
     66 
     67$User_Preferences{"FTPBACKUP"} = ""; 
     68$User_Preferences{"FTPUSER"} = ""; 
     69$User_Preferences{"FTPPASSWORD"} = ""; 
     70$User_Preferences{"FTPSUBDIR"} = ""; 
     71$User_Preferences{"FTPSERVER"} = ""; 
     72 
     73$User_Preferences{"SSHBACKUP"} = ""; 
     74$User_Preferences{"SSHUSER"} = ""; 
     75$User_Preferences{"SSHRSAKEY"} = ""; 
     76$User_Preferences{"SSHSUBDIR"} = ""; 
     77$User_Preferences{"SSHSERVER"} = ""; 
     78 
    6479open(FILE, "/etc/amportal.conf") || die "Failed to open amportal.conf\n"; 
    6580while (<FILE>) { 
     
    95110$webroot = $User_Preferences{"AMPWEBROOT"}; 
    96111 
     112# Provisioning root(s) and exclude list, if phone configuratoins should be backed up 
     113# 
     114$provroot = $User_Preferences{"AMPPROVROOT"}; 
     115$excludefile = $User_Preferences{"AMPPROVEXCLUDE"}; 
     116 
    97117# If and where to send the backup file once created (still left on local machine as well) 
    98118# 
     
    102122$ftpsubdir = $User_Preferences{"FTPSUBDIR"}; 
    103123$ftpserver = $User_Preferences{"FTPSERVER"}; 
     124 
     125$sshbackup = uc $User_Preferences{"SSHBACKUP"}; 
     126$sshuser = $User_Preferences{"SSHUSER"}; 
     127$sshrsakey = $User_Preferences{"SSHRSAKEY"}; 
     128$sshsubdir = $User_Preferences{"SSHSUBDIR"}; 
     129$sshserver = $User_Preferences{"SSHSERVER"}; 
    104130 
    105131################### END OF CONFIGURATION ####################### 
     
    110136#my $Stamp="$year$mon$mday.$hour.$min.$sec"; 
    111137my $Stamp=sprintf "%04d%02d%02d.%02d.%02d.%02d",$year,$mon,$mday,$hour,$min,$sec; 
    112  
    113138 
    114139if (scalar @ARGV > 1) 
     
    151176  } 
    152177} 
    153 #print "$Backup_Name $Backup_Voicemail $Backup_Recordings $Backup_Configurations $Backup_CDR $Backup_FOP\n"; 
    154  
    155178 
    156179  system ("/bin/rm -rf /tmp/ampbackups.$Stamp > /dev/null  2>&1"); 
     
    165188    system ($ast{'astvarlibdir'}."/bin/dumpastdb.php $Stamp > /dev/null"); 
    166189    system ("/bin/tar -Pcz -f /tmp/ampbackups.$Stamp/configurations.tar.gz ".$ast{'astvarlibdir'}."/agi-bin/ ".$ast{'astvarlibdir'}."/bin/ /etc/asterisk $webroot/admin /etc/amportal.conf /tmp/ampbackups.$Stamp/astdb.dump "); 
     190 
     191    if ($provroot ne "") { 
     192      $excludearg = ""; 
     193      if (-r $excludefile) { 
     194        $excludearg = "--exclude-from $excludefile "; 
     195      } 
     196      system ("/bin/tar -Pcz $excludearg -f /tmp/ampbackups.$Stamp/phoneconfig.tar.gz $provroot "); 
     197    } 
     198 
    167199    system ("mysqldump --add-drop-table -u $username -p$password --database $database > /tmp/ampbackups.$Stamp/asterisk.sql"); 
    168200  } 
     
    186218#       Note - the hardcoded full backup that cron does will overwrite each day at destination. 
    187219# 
    188 if ( $ftpbackup ne "YES" ) { 
    189   exit 
    190 
    191  
    192 open(FILE, ">$ftpfile") || die "Failed to open $ftpfile\n"; 
     220if ( $ftpbackup eq "YES" ) { 
     221  open(FILE, ">$ftpfile") || die "Failed to open $ftpfile\n"; 
    193222  
    194         printf FILE "user $ftpuser $ftppassword \n"; 
    195         printf FILE "binary\n"; 
    196   if ( $ftpsubdir ne "" ) { 
    197           printf FILE "cd $ftpsubdir \n"; 
    198  
    199         printf FILE "lcd /var/lib/asterisk/backups/$Backup_Name/\n"; 
    200         printf FILE "put $Stamp.tar.gz\n"; 
    201         printf FILE "bye\n"; 
    202         close(FILE); 
     223   printf FILE "user $ftpuser $ftppassword \n"; 
     224   printf FILE "binary\n"; 
     225     if ( $ftpsubdir ne "" ) { 
     226      printf FILE "cd $ftpsubdir \n"; 
     227     
     228     printf FILE "lcd /var/lib/asterisk/backups/$Backup_Name/\n"; 
     229     printf FILE "put $Stamp.tar.gz\n"; 
     230     printf FILE "bye\n"; 
     231     close(FILE); 
    203232  
    204         system ("ftp -n $ftpserver < $ftpfile > /dev/null  2>&1"); 
     233     system ("ftp -n $ftpserver < $ftpfile > /dev/null  2>&1"); 
    205234  
    206         #system ("/bin/rm -rf /tmp/ftp2cabana > /dev/null  2>&1"); 
    207  
    208  
     235      #system ("/bin/rm -rf /tmp/ftp2cabana > /dev/null  2>&1"); 
     236
     237 
     238if ( ($sshbackup eq "YES") && ($sshrsakey ne "") && ($sshserver ne "") ) { 
     239 
     240  if ($sshuser eq "") { 
     241    $sshuser = system("whoami"); 
     242  } 
     243  if ($sshsubdir ne "") { 
     244    system("/usr/bin/ssh -o StrictHostKeyChecking=no -i $sshrsakey $sshuser\@$sshserver mkdir -p $sshsubdir"); 
     245  } 
     246  system("/usr/bin/scp -o StrictHostKeyChecking=no -i $sshrsakey /var/lib/asterisk/backups/$Backup_Name/$Stamp.tar.gz $sshuser\@$sshserver:$sshsubdir"); 
     247
    209248 
    210249exit 0; 
  • modules/branches/2.3/backup/module.xml

    r3677 r3854  
    22  <rawname>backup</rawname> 
    33  <name>Backup &amp; Restore</name> 
    4   <version>2.1.1</version> 
     4  <version>2.1.2</version> 
    55  <type>tool</type> 
    66  <category>System Administration</category> 
     
    1212  </depends> 
    1313  <changelog> 
     14  *2.1.2* Add ability to scp backups to a server, add optional provisioning directory that can be backed up (no restore ability) 
    1415  *2.1.1* Remove core_users2astdb and core_devices2astdb, it isn't needed and corrupts resotred ampuser info 
    1516  *2.1* Actually, really, restore ASTDB now. Finally. Also add redirect_standard to avoid problems with TRBoE.