root/modules/branches/2.5/backup/bin/restoreastdb.php

Revision 6275, 1.9 kB (checked in by p_lindheimer, 5 years ago)

closes #2743, at least partially, so that we will not delete all the current entries if the restore dataset has an empty or blank astdb.dump file which otherise completely breaks the system

  • Property svn:mime-type set to text/html
  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1 #!/usr/bin/env php
2 <?php
3 // No use outputting anything, as env forces php headers to appear. Sigh.
4
5 global $argv;
6
7 // Astdb trees that should be deleted before the restore
8 //
9 $deltree = array(
10   'AMPUSER',
11   'DEVICE',
12   'CF',
13   'CFB',
14   'CFU',
15   'CW',
16   'DND',
17   'DAYNIGHT',
18 );
19
20 function getconf($filename) {
21         $file = file($filename);
22         foreach ($file as $line) {
23                 if (preg_match("/^\s*([\w]+)\s*=\s*\"?([\w\/\:\.\%-]*)\"?\s*([;#].*)?/",$line,$matches)) {
24                         $conf[ $matches[1] ] = $matches[2];
25                 }
26         }
27         return $conf;
28 }
29
30 $amp_conf = getconf("/etc/amportal.conf");
31
32 require_once($amp_conf['AMPWEBROOT']."/admin/common/php-asmanager.php");
33
34 $astman         = new AGI_AsteriskManager();
35 if (! $res = $astman->connect("127.0.0.1", $amp_conf["AMPMGRUSER"] , $amp_conf["AMPMGRPASS"])) {
36         unset( $astman );
37 }
38
39 if (!$argv[1] || strstr($argv[1], "/") || strstr($argv[1], "..")) {
40   // You must supply a single filename, which will be written to /tmp
41   exit;
42 }
43 $dump = file_get_contents("/tmp/ampbackups.".$argv[1]."/astdb.dump");
44
45 // Before restoring, let's clear out all of the current settings for the main objects
46 // but as a safety, if the dump file is empy, we won't clear it out.
47 //
48 if (!empty($dump)) {
49   $arr = explode("\n", $dump);
50   foreach ($deltree as $family) {
51     $astman->database_deltree($family);
52   }
53   foreach ($arr as $line) {
54     $result = preg_match("/\[(.+)\] \[(.+)\]/", $line, $matches);
55     // Now, the bad ones we know about are the ones that start with //, anything starting with SIP or IAX,
56     // and RG (which are only temporary anyway).
57     if (!isset($matches[1]) || $matches[1] == "") { continue; }
58     $pattern = "/(^\/\/)|(^\/IAX)|(^\/SIP)|(^\/RG)|(^\/BLKVM)|(^\/FM)|(^\/dundi)/";
59     if (preg_match($pattern, $matches[1])) { continue; }
60     preg_match("/(.+)\/(.+)$/", $matches[1], $famkey);
61     $famkey[1]=trim($famkey[1], '/');
62     $astman->database_put($famkey[1], $famkey[2], '"'.$matches[2].'"');
63   }
64 }
65
66 ?>
Note: See TracBrowser for help on using the browser.