Module: check_mk
Branch: master
Commit: e38214b77c6d113e1350d75cb5ac61e41b8ed0c5
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e38214b77c6d11…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Fri Jun 27 16:30:23 2014 +0200
FIX WATO snapshots: fixed missing files on restoring nagvis backup domains
---
.werks/947 | 9 +++++++++
ChangeLog | 3 ++-
web/htdocs/multitar.py | 40 +++++++++++++++++++++++++++++++++++++++-
3 files changed, 50 insertions(+), 2 deletions(-)
diff --git a/.werks/947 b/.werks/947
new file mode 100644
index 0000000..efe8bae
--- /dev/null
+++ b/.werks/947
@@ -0,0 +1,9 @@
+Title: WATO snapshots: fixed missing files on restoring nagvis backup domains
+Level: 1
+Component: wato
+Class: fix
+State: unknown
+Version: 1.2.5i5
+Date: 1403879357
+
+
diff --git a/ChangeLog b/ChangeLog
index 4918135..504013f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,8 +7,8 @@
* 0168 f5_bigip_pool: Added Wato configuration...
* 0995 raritan_pdu_outletcount: new check for outlet count of Raritan PX-2000 family
PDUs
* 0169 websphere_mq_channels,ebsphere_mq_queues: New Checks to monitor IBM Websphere
MQ Queues and Channels...
- * 0170 hp_proliant_power: New check to monitor the Power Meter on Prolaint Servers
and iLO Boards
* 1034 Always provide also 64 bit version of Windows agent
+ * 0170 hp_proliant_power: New check to monitor the Power Meter on Prolaint Servers
and iLO Boards
* 0994 FIX: agent plugin smart: fixed syntax error
* 0989 FIX: logwatch.ec: Fix forwarding multiple messages via syslog/TCP...
* 0943 FIX: if.include: fixed incorrect traffic percentage values in the check output
of if checks...
@@ -23,6 +23,7 @@
WATO:
* 0990 FIX: Fix HTTP error handling in bulk inventory...
* 1004 FIX: Fix exception when saving rules, caused by empty item
+ * 0947 FIX: WATO snapshots: fixed missing files on restoring nagvis backup domains
Reporting & Availability:
* 0991 FIX: Availability: optionally show time stamps as UNIX epoch time...
diff --git a/web/htdocs/multitar.py b/web/htdocs/multitar.py
index 241f4bd..d9ddd53 100644
--- a/web/htdocs/multitar.py
+++ b/web/htdocs/multitar.py
@@ -105,6 +105,7 @@ def get_file_content(the_tarfile, filename):
tar = tarfile.open(the_tarfile, "r")
return tar.extractfile(filename).read()
+
def extract_domains(tar, domains):
import subprocess
tar_domains = {}
@@ -180,7 +181,14 @@ def extract_domains(tar, domains):
full_path = "%s/%s" % (domain["prefix"], path)
if os.path.exists(full_path):
if what == "dir":
- wipe_directory(full_path)
+ exclude_files = []
+ for pattern in domain.get("exclude", []):
+ if "*" in pattern:
+ import glob
+ exclude_files.extend(glob.glob("%s/%s/%s" %
(domain["prefix"], path, pattern)))
+ else:
+ exclude_files.append("%s/%s/%s" %
(domain["prefix"], path, pattern))
+ cleanup_dir(full_path, exclude_files)
else:
os.remove(full_path)
return []
@@ -219,6 +227,7 @@ def extract_domains(tar, domains):
return domain["post_restore"]()
return []
+
total_errors = []
for what, abort_on_error, handler in [
("Permissions", True, lambda domain, tar_member:
check_domain(domain, tar_member)),
@@ -276,6 +285,35 @@ def extract(tar, components):
subtar = tarfile.open(fileobj = subtarstream)
subtar.extractall(target_dir)
+# Try to cleanup everything starting from the root_path
+# except the specific exclude files
+def cleanup_dir(root_path, exclude_files = []):
+ paths_to_remove = []
+ files_to_remove = []
+ for path, dirnames, filenames in os.walk(root_path):
+ for dirname in dirnames:
+ pathname = "%s/%s" % (path, dirname)
+ for entry in exclude_files:
+ if entry.startswith(pathname):
+ break
+ else:
+ paths_to_remove.append(pathname)
+ for filename in filenames:
+ filepath = "%s/%s" % (path, filename)
+ if filepath not in exclude_files:
+ files_to_remove.append(filepath)
+
+ paths_to_remove.sort()
+ files_to_remove.sort()
+
+ for path in paths_to_remove:
+ if os.path.exists(path) and os.path.isdir(path):
+ shutil.rmtree(path)
+
+ for filename in files_to_remove:
+ if os.path.dirname(filename) not in paths_to_remove:
+ os.remove(filename)
+
def wipe_directory(path):
for entry in os.listdir(path):
if entry not in [ '.', '..' ]: