Revision b3cc5117
Added by Viktor Gurov over 4 years ago
src/etc/inc/web/backup.inc | ||
---|---|---|
65 | 65 |
return $result; |
66 | 66 |
} |
67 | 67 |
|
68 |
function restore_rrddata() { |
|
69 |
global $config, $g, $rrdtool, $input_errors; |
|
70 |
foreach ($config['rrddata']['rrddatafile'] as $rrd) { |
|
71 |
if ($rrd['xmldata']) { |
|
72 |
$rrd_file = "{$g['vardb_path']}/rrd/{$rrd['filename']}"; |
|
73 |
$xml_file = preg_replace('/\.rrd$/', ".xml", $rrd_file); |
|
74 |
if (file_put_contents($xml_file, gzinflate(base64_decode($rrd['xmldata']))) === false) { |
|
75 |
log_error(sprintf(gettext("Cannot write %s"), $xml_file)); |
|
76 |
continue; |
|
77 |
} |
|
78 |
$output = array(); |
|
79 |
$status = null; |
|
80 |
exec("$rrdtool restore -f '{$xml_file}' '{$rrd_file}'", $output, $status); |
|
81 |
if ($status) { |
|
82 |
log_error("rrdtool restore -f '{$xml_file}' '{$rrd_file}' failed returning {$status}."); |
|
83 |
continue; |
|
84 |
} |
|
85 |
unlink($xml_file); |
|
86 |
} else if ($rrd['data']) { |
|
87 |
$rrd_file = "{$g['vardb_path']}/rrd/{$rrd['filename']}"; |
|
88 |
$rrd_fd = fopen($rrd_file, "w"); |
|
89 |
if (!$rrd_fd) { |
|
90 |
log_error(sprintf(gettext("Cannot write %s"), $rrd_file)); |
|
91 |
continue; |
|
92 |
} |
|
93 |
$data = base64_decode($rrd['data']); |
|
94 |
/* Try to decompress the data. */ |
|
95 |
$dcomp = @gzinflate($data); |
|
96 |
if ($dcomp) { |
|
97 |
/* If the decompression worked, write the decompressed data */ |
|
98 |
if (fwrite($rrd_fd, $dcomp) === false) { |
|
99 |
log_error(sprintf(gettext("fwrite %s failed"), $rrd_file)); |
|
100 |
continue; |
|
101 |
} |
|
102 |
} else { |
|
103 |
/* If the decompression failed, it wasn't compressed, so write raw data */ |
|
104 |
if (fwrite($rrd_fd, $data) === false) { |
|
105 |
log_error(sprintf(gettext("fwrite %s failed"), $rrd_file)); |
|
106 |
continue; |
|
107 |
} |
|
108 |
} |
|
109 |
if (fclose($rrd_fd) === false) { |
|
110 |
log_error(sprintf(gettext("fclose %s failed"), $rrd_file)); |
|
111 |
continue; |
|
112 |
} |
|
113 |
} |
|
114 |
} |
|
115 |
} |
|
116 |
|
|
117 |
function restore_xmldatafile($type='voucher') { |
|
118 |
global $config, $g; |
|
119 |
|
|
120 |
foreach ($config[$type]["{$type}data"]["xmldatafile"] as $file) { |
|
121 |
$basename = basename($file['filename']); |
|
122 |
$dirname = dirname($g['backuppath'][$type]); |
|
123 |
$xmldata_file = "{$dirname}/{$basename}"; |
|
124 |
if (file_put_contents($xmldata_file, gzinflate(base64_decode($file['data']))) === false) { |
|
125 |
log_error(sprintf(gettext("Cannot write %s"), $xmldata_file)); |
|
126 |
continue; |
|
127 |
} |
|
128 |
} |
|
129 |
} |
|
130 |
|
|
131 | 68 |
function backup_xmldatafile($tab=false, $type='voucher') { |
132 | 69 |
global $g; |
133 | 70 |
|
... | ... | |
206 | 143 |
$name = "{$post['backuparea']}-{$name}"; |
207 | 144 |
} else if (array_key_exists($post['backuparea'], $g['backuppath']) && $post['backupdata']) { |
208 | 145 |
$data = backup_config_section($post['backuparea']); |
146 |
$data = clear_tagdata($post['backuparea'], $data); |
|
209 | 147 |
$dataxml = backup_xmldatafile(false, $post['backuparea']); |
210 | 148 |
$closing_tag = "</{$post['backuparea']}>"; |
211 | 149 |
$data = str_replace($closing_tag, $dataxml . $closing_tag, $data); |
... | ... | |
217 | 155 |
} |
218 | 156 |
} |
219 | 157 |
|
220 |
//unlock($lockbckp); |
|
221 |
|
|
222 |
/* |
|
223 |
* Backup RRD Data |
|
224 |
*/ |
|
225 |
|
|
226 |
/* If the config on disk had rrddata tags already, remove that section first. |
|
227 |
* See https://redmine.pfsense.org/issues/8994 and |
|
228 |
* https://redmine.pfsense.org/issues/10508 */ |
|
229 |
$data = preg_replace("/[[:blank:]]*<rrddata>.*<\\/rrddata>[[:blank:]]*\n*/s", "", $data); |
|
230 |
$data = preg_replace("/[[:blank:]]*<rrddata\\/>[[:blank:]]*\n*/", "", $data); |
|
158 |
if ($post['backuparea'] != "rrddata") { |
|
159 |
$data = clear_tagdata('rrd', $data); |
|
160 |
} |
|
231 | 161 |
|
232 | 162 |
if (!$post['backuparea'] && $post['backupdata']) { |
233 | 163 |
foreach ($g['backuppath'] as $bk => $path) { |
234 | 164 |
if (!empty($config[$bk])) { |
165 |
$data = clear_tagdata($bk, $data); |
|
235 | 166 |
$dataxml = backup_xmldatafile(true, $bk); |
236 | 167 |
$closing_tag = "\t</{$bk}>"; |
237 | 168 |
$data = str_replace($closing_tag, $dataxml . $closing_tag, $data); |
... | ... | |
239 | 170 |
} |
240 | 171 |
} |
241 | 172 |
|
242 |
if ($post['backuparea'] !== "rrddata" && !$post['donotbackuprrd']) {
|
|
173 |
if (($post['backuparea'] != "rrddata") && !$post['donotbackuprrd']) {
|
|
243 | 174 |
$rrd_data_xml = rrd_data_xml(); |
244 | 175 |
$closing_tag = "</" . $g['xml_rootobj'] . ">"; |
245 | 176 |
$data = str_replace($closing_tag, $rrd_data_xml . $closing_tag, $data); |
Also available in: Unified diff
Backup extra data fixes. Issue #11050