Compare commits

...

5 Commits

Author SHA1 Message Date
Vincent Bidolet
01bcf68d13 adding *better* filtering 2023-11-13 18:52:02 +01:00
Vincent Bidolet
f2990ff23b adding *better* filtering 2023-11-13 18:50:09 +01:00
Vincent Bidolet
116af4c0ea adding *better* filtering 2023-11-13 17:22:19 +01:00
Vincent Bidolet
6bb11f4db2 adding *better* filtering 2023-11-13 17:20:36 +01:00
Vincent Bidolet
16a0844c57 adding *better* filtering 2023-11-13 17:19:50 +01:00

24
main.py
View File

@@ -60,10 +60,11 @@ def read_config_file(filepath: str = "configuration.ini"):
arguments.remotehost = parser["restic"]["remotehost"] arguments.remotehost = parser["restic"]["remotehost"]
arguments.repository = parser["restic"]["repository"] arguments.repository = parser["restic"]["repository"]
arguments.passwordfile = parser["restic"]["passwordfile"] arguments.passwordfile = parser["restic"]["passwordfile"]
if "dryrun" in parser["restic"]:
arguments.dryrun = (parser["restic"]["dryrun"].lower() == "true" or parser["restic"]["dryrun"] > 0)
else:
arguments.dryrun = False arguments.dryrun = False
if "dryrun" in parser["restic"] and (parser["restic"]["dryrun"].lower() == "true" \
or (parser["restic"]["dryrun"].isdigit() and parser["restic"]["dryrun"] > 0)):
arguments.dryrun = True
def restic_backup(dirpath: str, tagslist: list = None): def restic_backup(dirpath: str, tagslist: list = None):
@@ -198,12 +199,6 @@ def backup_services(servicename: str, servicesdict: dict, composefilepath: str)
if len(servicesdict[servicename]["must_before"]): if len(servicesdict[servicename]["must_before"]):
for dependencie in servicesdict[servicename]["must_before"]: for dependencie in servicesdict[servicename]["must_before"]:
if arguments.bindexclude not in ("", None) and dependencie.find(arguments.bindexclude) != -1:
# on a un filtre d'exclusion et il matche, donc on ne backup pas
continue
elif arguments.bindinclude not in ("", None) and dependencie.find(arguments.bindinclude) != -1:
#on a un filtre d'inclusion et il ne matche pas, donc on ne backup pas
continue
backup_services(dependencie, servicesdict, composefilepath) backup_services(dependencie, servicesdict, composefilepath)
# TODO: faire la sauvegarde # TODO: faire la sauvegarde
@@ -212,6 +207,17 @@ def backup_services(servicename: str, servicesdict: dict, composefilepath: str)
if "Binds" in container.attrs["HostConfig"] and len(container.attrs["HostConfig"]["Binds"]): if "Binds" in container.attrs["HostConfig"] and len(container.attrs["HostConfig"]["Binds"]):
for bind in container.attrs["HostConfig"]["Binds"]: for bind in container.attrs["HostConfig"]["Binds"]:
bindpath = bind.split(":")[0] bindpath = bind.split(":")[0]
if arguments.bindexclude not in ("", None) and bindpath.find(
arguments.bindexclude) != -1:
print(f" {bindpath} is matching the exclusion pattern, skipping.")
# on a un filtre d'exclusion et il matche, donc on ne backup pas
pass
elif arguments.bindinclude not in ("", None) and not bindpath.find(
arguments.bindinclude) != -1:
print(f" {bindpath} is not matching the inclusion pattern, skipping.")
# on a un filtre d'inclusion et il ne matche pas, donc on ne backup pas
pass
else:
print(f" backup of {bindpath}") print(f" backup of {bindpath}")
restic_backup(dirpath=bindpath, tagslist=[servicename]) restic_backup(dirpath=bindpath, tagslist=[servicename])