Changeset 8453
- Timestamp:
- 12/27/09 08:31:51 (3 years ago)
- Files:
-
- modules/branches/2.6/backup/bin/ampbackup.php (modified) (7 diffs)
- modules/branches/2.6/backup/module.xml (modified) (2 diffs)
- modules/branches/2.6/backup/page.backup.php (modified) (1 diff)
- modules/branches/2.6/backup/schedule_functions.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
modules/branches/2.6/backup/bin/ampbackup.php
r8445 r8453 32 32 $amp_conf=getconf((isset($_ENV['FREEPBXCONFIG']) && strlen($_ENV['FREEPBXCONFIG']))?$_ENV['FREEPBXCONFIG']:'/etc/amportal.conf'); 33 33 $ast_conf=getconf((isset($_ENV['ASTERISKCONFIG']) && strlen($_ENV['ASTERISKCONFIG']))?$_ENV['ASTERISKCONFIG']:'/etc/asterisk/asterisk.conf'); 34 //default some options if they are blank 34 35 if(!isset($amp_conf['AMPBACKADMIN'])){$amp_conf['AMPBACKADMIN']=true;} 36 if(!isset($amp_conf['AMPBACKUPEMAILFROM'])){$amp_conf['AMPBACKUPEMAILFROM']='backup@freepbx.org';} 37 if(!isset($amp_conf['AMPBACKUPEMAILMAX'])){$amp_conf['AMPBACKUPEMAILMAX']='10MB';} 35 38 //var_dump($amp_conf); 36 39 //$opts=getOpts(); … … 40 43 if($amp_conf['AMPBACKUPSUDO']==true){$sudo='/usr/bin/sudo';} 41 44 //connect to database 42 include ('DB.php');43 $db = DB::connect('mysql://'.$amp_conf['AMPDBUSER'].':'.$amp_conf['AMPDBPASS'].'@'.$amp_conf['AMPDBHOST'].'/'.$amp_conf['AMPDBNAME']);// attempt connection45 include_once('DB.php'); 46 if(!isset($db)){$db = DB::connect('mysql://'.$amp_conf['AMPDBUSER'].':'.$amp_conf['AMPDBPASS'].'@'.$amp_conf['AMPDBHOST'].'/'.$amp_conf['AMPDBNAME']);} // attempt connection 44 47 45 48 if($argc == 1){//no args recieved - show help text 46 echo "\n"; 47 echo "# ampbackup.php Backup-set-ID \n"; 48 echo "This script Reads the backup options from the BackupTable then runs the backup picking up the items that were turned.\n"; 49 echo "\n";echo " --OR-- \n";echo "\n"; 50 echo "The program is called from the backup.php script and implemented immediately as such:\n"; 51 echo "# ampbackup.php Name Voicemail(yes/no) Recordings(yes/no) Config_files(yes/no) CDR(yes/no) FOP(yes/no)\n"; 52 echo " \n"; 53 echo "example: ampbackup.php \"My_Nightly_Backup\" yes yes no no yes\n"; 54 exit(1); 49 showopts(); 55 50 }elseif($argc == 2){//one arg recievied. Hmm, this sounds like a backup schedules id... Lets look in the DB for more details 56 51 $sql = "SELECT Name, Voicemail, Recordings, Configurations, CDR, FOP from Backup where ID= ?"; … … 74 69 75 70 //if all options are set to no/false, return an error 76 if(!$opts['voicemail']&&!$opts['recordings']&&!$opts['configs']&&!$opts['cdr']&&!$opts['fop']){echo " You need to set at least one option to yes\n";exit(1);}71 if(!$opts['voicemail']&&!$opts['recordings']&&!$opts['configs']&&!$opts['cdr']&&!$opts['fop']){echo "Backup Error: You need to set at least one option to yes\n";showopts();} 77 72 system('/bin/rm -rf /tmp/ampbackups.'.$opts['now'].' > /dev/null 2>&1');//remove stale backup 78 73 system('/bin/mkdir /tmp/ampbackups.'.$opts['now'].' > /dev/null 2>&1');//create directory for current backup … … 93 88 if ($amp_conf['AMPPROVROOT']){ 94 89 $xfile=''; 95 if( $amp_conf['AMPPROVEXCLUDE']){$xfile='--exclude-from '.$amp_conf['AMPPROVEXCLUDE'];};//file containing exclude list96 if( $amp_conf['AMPPROVEXCLUDELIST']){90 if(isset($amp_conf['AMPPROVEXCLUDE']) && $amp_conf['AMPPROVEXCLUDE']){$xfile='--exclude-from '.$amp_conf['AMPPROVEXCLUDE'];};//file containing exclude list 91 if(isset($amp_conf['AMPPROVEXCLUDELIST']) && $amp_conf['AMPPROVEXCLUDELIST']){ 97 92 $exclude=''; 98 93 $ex=explode(' ',$amp_conf['AMPPROVEXCLUDELIST']); … … 136 131 } 137 132 133 //SSH backup 138 134 if(isset($amp_conf['SSHBACKUP']) && $amp_conf['SSHBACKUP']=='yes'){ 139 135 if(($amp_conf['SSHRSAKEY']!='') && ($amp_conf['SSHSERVER']!='')){ … … 148 144 } 149 145 150 146 //EMAIL backup 147 if($amp_conf['AMPBACKUPEMAIL']=='yes' && isset($amp_conf['AMPBACKUPEMAILADDR'])){ 148 if(filesize($opts['budir'].'/'.$opts['name']) <= size2bytes(strtoupper($amp_conf['AMPBACKUPEMAILMAX']))){ 149 //credit to: http://articles.sitepoint.com/print/advanced-email-php 150 $hostname=exec('/bin/hostname',$name); 151 $subject = 'FreePBX backup of '.$hostname; 152 $emessage = sprintf("Hello. Attached, please find your FreePBX backup file from backup set: %s, run on %s, at %s",$opts['name'],$hostname,date('Y-m-d h:i:sa')); 153 154 // Obtain file info 155 $filename=$opts['budir'].'/'.$opts['name'].'/'.$opts['now'].'.tar.gz'; 156 exec('file -bi '.$filename,$type); 157 $file_type=$type[0]; 158 159 $headers = 'From: '.$amp_conf['AMPBACKUPEMAILFROM']; 160 // Read the file to be attached ('rb' = read binary) 161 $file = fopen($filename,'rb'); 162 $data = fread($file,filesize($filename)); 163 fclose($file); 164 165 // Generate a random boundary string 166 $mime_boundary='==Multipart_Boundary_x'.md5(time()).'x'; 167 // Add the headers for a file attachment 168 $headers.="\nMIME-Version: 1.0\n"; 169 $headers.="Content-Type: multipart/mixed;\n"; 170 $headers.=" boundary=\"{$mime_boundary}\""; 171 // Add a multipart boundary above the plain message 172 $message="This is a multi-part message in MIME format.\n\n"; 173 $message.="--{$mime_boundary}\n"; 174 $message.="Content-Type: text/plain; charset=\"iso-8859-1\"\n"; 175 $message.="Content-Transfer-Encoding: 7bit\n\n"; 176 $message.=$emessage . "\n\n"; 177 // Base64 encode the file data 178 $data = chunk_split(base64_encode($data)); 179 // Add file attachment to the message 180 $message.="--{$mime_boundary}\n"; 181 $message.="Content-Type: {$file_type};\n"; 182 $message.=' name="'.$opts['now'].'.tar.gz'."\"\n"; 183 //$message.="Content-Disposition: attachment;\n"; 184 //$message.=" filename=\"{$file}\"\n"; 185 $message.="Content-Transfer-Encoding: base64\n\n"; 186 $message.=$data . "\n\n"; 187 $message.="--{$mime_boundary}--\n"; 188 189 //debug output 190 //echo "To:\n";echo $amp_conf['AMPBACKUPEMAILADDR'];echo "\n\nSubject:\n";echo $subject;echo "\n\nMessage:\n";echo $message;echo "\n\nHeaders:\n";echo $headers."\n"; 191 // Send the message 192 mail($amp_conf['AMPBACKUPEMAILADDR'], $subject, $message, $headers); 193 } 194 } 195 196 197 function size2bytes($str){ 198 $bytes=0; 199 $bytes_array=array('B' => 1, 'KB' => 1024, 'MB' => 1024 * 1024, 'GB' => 1024 * 1024 * 1024, 200 'TB' => 1024 * 1024 * 1024 * 1024, 'PB' => 1024 * 1024 * 1024 * 1024 * 1024,); 201 $bytes=floatval($str); 202 if(preg_match('#([KMGTP]?B)$#si', $str, $matches) && !empty($bytes_array[$matches[1]])){ 203 $bytes*=$bytes_array[$matches[1]]; 204 } 205 $bytes=intval(round($bytes, 2)); 206 return $bytes; 207 } 208 209 function showopts(){ 210 echo "\n"; 211 echo "# ampbackup.php Backup-set-ID \n"; 212 echo "This script Reads the backup options from the BackupTable then runs the backup picking up the items that were turned.\n"; 213 echo "\n";echo " --OR-- \n";echo "\n"; 214 echo "The program is called from the backup.php script and implemented immediately as such:\n"; 215 echo "# ampbackup.php Name Voicemail(yes/no) Recordings(yes/no) Config_files(yes/no) CDR(yes/no) FOP(yes/no)\n"; 216 echo " \n"; 217 echo "example: ampbackup.php \"My_Nightly_Backup\" yes yes no no yes\n"; 218 exit(1); 219 } 151 220 function getconf($filename) { 152 221 $file = file($filename); … … 172 241 173 242 function dbug($disc=null,$msg=null){ 174 $debug= false;243 $debug=true; 175 244 if ($debug){ 176 245 $fh = fopen("/tmp/freepbx_debug.log", 'a') or die("can't open file"); modules/branches/2.6/backup/module.xml
r8241 r8453 2 2 <rawname>backup</rawname> 3 3 <name>Backup & Restore</name> 4 <version>2.6.0. 3</version>4 <version>2.6.0.4</version> 5 5 <publisher>FreePBX</publisher> 6 6 <license>GPLv2+</license> … … 15 15 </depends> 16 16 <changelog> 17 *2.6.0.4* #3975 - multipal backup improvements 17 18 *2.6.0.3* #3839 18 19 *2.6.0.2* #3577 modules/branches/2.6/backup/page.backup.php
r7470 r8453 74 74 75 75 $backup_schedule=$_REQUEST['backup_schedule']; 76 $mins= $_REQUEST['mins'];77 $hours= $_REQUEST['hours'];78 $days= $_REQUEST['days'];79 $months= $_REQUEST['months'];80 $weekdays= $_REQUEST['weekdays'];76 $mins=isset($_REQUEST['mins'])?$_REQUEST['mins']:''; 77 $hours=isset($_REQUEST['hours'])?$_REQUEST['hours']:''; 78 $days=isset($_REQUEST['days'])?$_REQUEST['days']:''; 79 $months=isset($_REQUEST['months'])?$_REQUEST['months']:''; 80 $weekdays=isset($_REQUEST['weekdays'])?$_REQUEST['weekdays']:''; 81 81 82 82 $backup_options[]=$_REQUEST['bk_voicemail']; modules/branches/2.6/backup/schedule_functions.php
r8440 r8453 297 297 if ($Backup_Parms[1]=="now") 298 298 { 299 $Cron_Script=$asterisk_conf['astvarlibdir']."/bin/ampbackup.p l'$Backup_Parms[0]' $backup_options[0] $backup_options[1] $backup_options[2] $backup_options[3] $backup_options[4]";299 $Cron_Script=$asterisk_conf['astvarlibdir']."/bin/ampbackup.php '$Backup_Parms[0]' $backup_options[0] $backup_options[1] $backup_options[2] $backup_options[3] $backup_options[4]"; 300 300 //echo "$Cron_Script"; 301 exec($Cron_Script); 301 //list($Backup_Parms[0], $backup_options[0], $backup_options[1], $backup_options[2], $backup_options[3], $backup_options[4])=$argv; 302 $argv=array('', $Backup_Parms[0], $backup_options[0], $backup_options[1], $backup_options[2], $backup_options[3], $backup_options[4]); 303 $argc=count($argv); 304 include($asterisk_conf['astvarlibdir'].'/bin/ampbackup.php'); 305 //exec($Cron_Script); 302 306 } 303 307 $sql = "INSERT INTO Backup (Name, Voicemail, Recordings, Configurations, CDR, FOP, Minutes, Hours, Days, Months,Weekdays, Command, Method ) VALUES ("; … … 327 331 global $asterisk_conf; 328 332 if ($backup_schedule=="hourly") 329 $Cron_String="0 * * * * ".$asterisk_conf['astvarlibdir']."/bin/ampbackup.p l";333 $Cron_String="0 * * * * ".$asterisk_conf['astvarlibdir']."/bin/ampbackup.php"; 330 334 else if ($backup_schedule=="daily") 331 $Cron_String="0 0 * * * ".$asterisk_conf['astvarlibdir']."/bin/ampbackup.p l";335 $Cron_String="0 0 * * * ".$asterisk_conf['astvarlibdir']."/bin/ampbackup.php"; 332 336 else if ($backup_schedule=="weekly") 333 $Cron_String="0 0 * * 0 ".$asterisk_conf['astvarlibdir']."/bin/ampbackup.p l";337 $Cron_String="0 0 * * 0 ".$asterisk_conf['astvarlibdir']."/bin/ampbackup.php"; 334 338 else if ($backup_schedule=="monthly") 335 $Cron_String="0 0 1 * * ".$asterisk_conf['astvarlibdir']."/bin/ampbackup.p l";339 $Cron_String="0 0 1 * * ".$asterisk_conf['astvarlibdir']."/bin/ampbackup.php"; 336 340 else if ($backup_schedule=="yearly") 337 $Cron_String="0 0 1 1 * ".$asterisk_conf['astvarlibdir']."/bin/ampbackup.p l";341 $Cron_String="0 0 1 1 * ".$asterisk_conf['astvarlibdir']."/bin/ampbackup.php"; 338 342 else if ($backup_schedule=="follow_schedule") 339 343 { … … 369 373 $weekdays_string.=":$value:"; 370 374 } 371 372 $cron_mins_string=trim($mins_string,":"); 375 $cron_mins_string=trim($mins_string,":"); 373 376 $cron_hours_string=trim($hours_string,":"); 374 377 $cron_days_string=trim($days_string,":"); 375 378 $cron_months_string=trim($months_string,":"); 376 379 $cron_weekdays_string=trim($weekdays_string,":"); 377 $Cron_String=str_replace("::", ",", "$cron_mins_string $cron_hours_string $cron_days_string $cron_months_string $cron_weekdays_string ".$asterisk_conf['astvarlibdir']."/bin/ampbackup.p l");380 $Cron_String=str_replace("::", ",", "$cron_mins_string $cron_hours_string $cron_days_string $cron_months_string $cron_weekdays_string ".$asterisk_conf['astvarlibdir']."/bin/ampbackup.php"); 378 381 } 379 382 else if ($backup_schedule=="now") 380 $Cron_String="0 0 0 0 0 ".$asterisk_conf['astvarlibdir']."/bin/ampbackup.pl";381 $Backup_String[]= "$name";382 $Backup_String[]= "$backup_schedule";383 $Backup_String[]= "$mins_string";384 $Backup_String[]= "$hours_string";385 $Backup_String[]= "$days_string";386 $Backup_String[]= "$months_string";387 $Backup_String[]= "$weekdays_string";388 $Backup_String[]= "$Cron_String";383 $Cron_String="0 0 0 0 0 ".$asterisk_conf['astvarlibdir']."/bin/ampbackup.php"; 384 $Backup_String[]=$name; 385 $Backup_String[]=$backup_schedule; 386 $Backup_String[]=isset($mins_string)?$mins_string:''; 387 $Backup_String[]=isset($hours_string)?$hours_string:''; 388 $Backup_String[]=isset($days_string)?$days_string:''; 389 $Backup_String[]=isset($months_string)?$months_string:''; 390 $Backup_String[]=isset($weekdays_string)?$weekdays_string:''; 391 $Backup_String[]=$Cron_String; 389 392 390 393 return ($Backup_String); … … 412 415 function Show_Backup_Options($ID="") 413 416 { 417 $tabindex=0; 414 418 if ($ID==""){ 415 419 $name=""; $voicemail="no"; $sysrecordings="no"; $sysconfig="no"; $cdr="no"; $fop="no";} … … 615 619 $backup_times=Get_Backup_Times($BackupID); 616 620 foreach ($backup_times as $bk_times) 617 $Minutes="$bk_times[0]"; $Hours="$bk_times[1]"; $Days="$bk_times[2]"; $Months="$bk_times[3]"; $Weekdays="$bk_times[4]"; $Method="$bk_times[5]"; 621 $Minutes=$bk_times[0]?"$bk_times[0]":''; 622 $Hours=$bk_times[1]?"$bk_times[1]":''; 623 $Days=$bk_times[2]?"$bk_times[2]":''; 624 $Months=$bk_times[3]?"$bk_times[3]":''; 625 $Weekdays=$bk_times[4]?"$bk_times[4]":''; 626 $Method=$bk_times[5]?"$bk_times[5]":''; 618 627 619 628 }
