mirror of
https://github.com/FAUSheppy/athq-vm-management
synced 2025-12-06 05:41:35 +01:00
feat: parse complex backup paths
This commit is contained in:
20
backup.py
20
backup.py
@@ -29,26 +29,34 @@ def createBackupScriptStructure(backupList, baseDomain=""):
|
|||||||
# add base paths for rsync filter (e.g. /var/ for /var/lib/anything/)
|
# add base paths for rsync filter (e.g. /var/ for /var/lib/anything/)
|
||||||
# because we use - /** for excluding anything else #
|
# because we use - /** for excluding anything else #
|
||||||
basePaths = []
|
basePaths = []
|
||||||
|
fullPaths = []
|
||||||
for p in paths:
|
for p in paths:
|
||||||
|
|
||||||
if not os.path.isabs(p):
|
cur = p
|
||||||
|
options = None
|
||||||
|
if type(p) == dict:
|
||||||
|
cur = p["path"]
|
||||||
|
options = p["options"]
|
||||||
|
|
||||||
|
if not os.path.isabs(cur):
|
||||||
print("WARNING: Non-absolute path for backup {} (skipping..)".format(p))
|
print("WARNING: Non-absolute path for backup {} (skipping..)".format(p))
|
||||||
continue
|
continue
|
||||||
elif "//" in p:
|
elif "//" in cur:
|
||||||
print("WARNING: Illegal double-slash in backup path {} (skipping..)".format(p))
|
print("WARNING: Illegal double-slash in backup path {} (skipping..)".format(p))
|
||||||
continue
|
continue
|
||||||
elif "/" == p:
|
elif "/" == cur:
|
||||||
print("WARNING: Root (/) is not allowed as backup path (skipping..)".format(p))
|
print("WARNING: Root (/) is not allowed as backup path (skipping..)".format(p))
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
basePaths.append("/{}/".format(p.split("/")[1]))
|
basePaths.append("/{}/".format(cur.split("/")[1]))
|
||||||
|
fullPaths.append(cur)
|
||||||
|
|
||||||
# keep order (important!)
|
# keep order (important!)
|
||||||
paths = list(set(basePaths)) + [ p.rstrip("/") + "/***" for p in paths ]
|
paths = list(set(basePaths)) + [ p.rstrip("/") + "/***" for p in fullPaths ]
|
||||||
|
|
||||||
rsyncScript = rsyncScriptTemplate.render(hostname=hostname, token=icingaToken,
|
rsyncScript = rsyncScriptTemplate.render(hostname=hostname, token=icingaToken,
|
||||||
hostname_base=hostnameBase)
|
hostname_base=hostnameBase)
|
||||||
rsyncFilter = rsyncFilterTemplate.render(paths=paths)
|
rsyncFilter = rsyncFilterTemplate.render(paths=fullPaths)
|
||||||
|
|
||||||
path = "./build/backup/"
|
path = "./build/backup/"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user