Module: check_mk
Branch: master
Commit: ff98ddeab25831ba4d752105e16e99b724cd1cd3
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ff98ddeab25831…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Tue Jan 14 16:58:39 2014 +0100
FIX wato snapshots: snapshot restore no longer fails with older python versions
Python versions <= 2.6.6 had problems on restoring snapshots files.<br>
The python tarfile module crashed when it tried to unpack tarfiles with no
content.<br>
The new implementation now uses the tar from the command line instead of the python
tarfile module.
---
.werks/256 | 11 +++++++++++
ChangeLog | 1 +
web/htdocs/multitar.py | 32 +++++++++++++++++---------------
web/plugins/wato/backup_domains.py | 2 ++
4 files changed, 31 insertions(+), 15 deletions(-)
diff --git a/.werks/256 b/.werks/256
new file mode 100644
index 0000000..ae07b2b
--- /dev/null
+++ b/.werks/256
@@ -0,0 +1,11 @@
+Title: wato snapshots: snapshot restore no longer fails with older python versions
+Level: 1
+Component: wato
+Class: fix
+State: unknown
+Version: 1.2.5i1
+Date: 1389714765
+
+Python versions <= 2.6.6 had problems on restoring snapshots files.<br>
+The python tarfile module crashed when it tried to unpack tarfiles with no
content.<br>
+The new implementation now uses the tar from the command line instead of the python
tarfile module.
diff --git a/ChangeLog b/ChangeLog
index 35e92bd..008478e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -174,6 +174,7 @@
* 0422 FIX: Fixed numbers shown in log entries of bulk inventory...
* 0252 FIX: ESX vSphere configuration: Fixed non-working configuration parameters...
* 0456 FIX: Column was too short...
+ * 0256 FIX: wato snapshots: snapshot restore no longer fails with older python
versions...
Notifications:
* 0362 sms: now searching PATH for sendsms and smssend commands...
diff --git a/web/htdocs/multitar.py b/web/htdocs/multitar.py
index e818524..45a991e 100644
--- a/web/htdocs/multitar.py
+++ b/web/htdocs/multitar.py
@@ -98,10 +98,12 @@ def get_file_content(tarfilename, filename):
return tar.extractfile(filename).read()
def extract_domains(tar, domains):
+ import subprocess
tar_domains = {}
for member in tar.getmembers():
try:
- tar_domains[member.name[:-7]] = member
+ if member.name.endswith(".tar.gz"):
+ tar_domains[member.name[:-7]] = member
except Exception, e:
pass
@@ -133,21 +135,27 @@ def extract_domains(tar, domains):
# The complete tar file never fits in stringIO buffer..
tar.extract(tar_member, restore_dir)
- subtar = tarfile.open("%s/%s" % (restore_dir, tar_member.name))
- # Set group id of extracted files, except base paths..
- for entry in subtar.getmembers():
- full_path = prefix + "/" + entry.name
+ # Older versions of python tarfile handle empty subtar archives :(
+ # This won't work: subtar = tarfile.open("%s/%s" % (restore_dir,
tar_member.name))
+ p = subprocess.Popen("tar tzf %s/%s" % (restore_dir, tar_member.name),
shell = True, stdout = subprocess.PIPE)
+ stdout, stderr = p.communicate()
+ for line in stdout:
+ full_path = prefix + "/" + line
path_tokens = full_path.split("/")
check_exists_or_writable(path_tokens)
# Cleanup
os.unlink("%s/%s" % (restore_dir, tar_member.name))
- return len(errors) == 0, errors
+ return errors
def cleanup_domain(domain):
+ # Some domains, e.g. authorization, do not get a cleanup
+ if domain.get("cleanup") == False:
+ return
+
def path_valid(prefix, path):
if path.startswith("/") or path.startswith(".."):
return False
@@ -170,21 +178,15 @@ def extract_domains(tar, domains):
return
# The complete tar.gz file never fits in stringIO buffer..
tar.extract(tar_member, restore_dir)
- subtar = tarfile.open("%s/%s" % (restore_dir, tar_member.name))
- subtar.extractall(target_dir)
-
- # Set group id of extracted files, except base paths..
- base_paths = [path[1] for path in domain.get("paths") if path[0] ==
"dir"]
- for entry in subtar.getmembers():
- if entry.name not in base_paths:
- os.chown("%s/%s" % (target_dir, entry.name), -1, gid)
+ p = subprocess.Popen("tar xzf %s/%s -C %s" % (restore_dir,
tar_member.name, target_dir), shell = True)
+ p.communicate()
# Check write permissions for target directories and files
errors = []
for name, tar_member in tar_domains.items():
if name in domains:
- result, dom_errors = check_domain_permissions(domains[name], tar_member)
+ dom_errors = check_domain_permissions(domains[name], tar_member)
errors.extend(dom_errors)
if len(errors):
errors = list(set(errors))
diff --git a/web/plugins/wato/backup_domains.py b/web/plugins/wato/backup_domains.py
index 771e60e..19b103d 100644
--- a/web/plugins/wato/backup_domains.py
+++ b/web/plugins/wato/backup_domains.py
@@ -30,6 +30,7 @@ if not defaults.omd_root:
("file", "auth.secret"),
("file", "auth.serials")
],
+ "cleanup" : False,
"default" : True
}})
else:
@@ -61,6 +62,7 @@ else:
("file", "auth.secret"),
("file", "auth.serials")
],
+ "cleanup" : False,
"default" : True
},
"personalsettings": {