Project

General

Profile

« Previous | Next » 

Revision 08877746

Added by Darren Embry about 13 years ago

restore_rrddata() adds log_error calls and uses -f

View differences:

usr/local/www/diag_backup.php
84 84

  
85 85
function restore_rrddata() {
86 86
	global $config, $g, $rrdtool, $input_errors;
87

  
88
	log_error("restore_rrddata has been called.");
89 87
	foreach($config['rrddata']['rrddatafile'] as $rrd) {
90 88
		if ($rrd['xmldata']) {
91
			log_error("rrd contains xmldata.");
92 89
			$rrd_file = "{$g['vardb_path']}/rrd/{$rrd['filename']}";
93 90
			$xml_file = preg_replace('/\.rrd$/', ".xml", $rrd_file);
94
			log_error("\$xml_file = \"$xml_file\"");
95
			log_error("\$rrd_file = \"$rrd_file\"");
96
			file_put_contents($xml_file, gzinflate(base64_decode($rrd['xmldata'])));
97
			exec("$rrdtool restore '{$xml_file}' '{$rrd_file}'");
91
			if (file_put_contents($xml_file, gzinflate(base64_decode($rrd['xmldata']))) === false) {
92
				log_error("Cannot write $xml_file");
93
				continue;
94
			}
95
			$output = array();
96
			$status = null;
97
			exec("$rrdtool restore -f '{$xml_file}' '{$rrd_file}'", $output, $status);
98
			if ($status) {
99
				log_error("rrdtool restore -f failed returning $status");
100
				continue;
101
			}
98 102
			unlink($xml_file);
99 103
		}
100 104
		else if ($rrd['data']) {
101
			log_error("rrd contains (non-xml) data.");
102 105
			$rrd_file = "{$g['vardb_path']}/rrd/{$rrd['filename']}";
103
			log_error("\$rrd_file = \"$rrd_file\"");
104 106
			$rrd_fd = fopen($rrd_file, "w");
107
			if (!$rrd_fd) {
108
				log_error("Cannot write $rrd_file");
109
				continue;
110
			}
105 111
			$data = base64_decode($rrd['data']);
106 112
			/* Try to decompress the data. */
107 113
			$dcomp = @gzinflate($data);
108 114
			if ($dcomp) {
109 115
				/* If the decompression worked, write the decompressed data */
110
				fwrite($rrd_fd, $dcomp);
116
				if (fwrite($rrd_fd, $dcomp) === false) {
117
					log_error("fwrite $rrd_file failed");
118
					continue;
119
				}
111 120
			} else {
112 121
				/* If the decompression failed, it wasn't compressed, so write raw data */
113
				fwrite($rrd_fd, $data);
122
				if (fwrite($rrd_fd, $data) === false) {
123
					log_error("fwrite $rrd_file failed");
124
					continue;
125
				}
126
			}
127
			if (fclose($rrd_fd) === false) {
128
				log_error("fclose $rrd_file failed");
129
				continue;
114 130
			}
115
			fclose($rrd_fd);
116 131
		}
117 132
	}
118 133
}

Also available in: Unified diff