Compare commits
7 Commits
973d5487a0
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01bcf68d13 | ||
|
|
f2990ff23b | ||
|
|
116af4c0ea | ||
|
|
6bb11f4db2 | ||
|
|
16a0844c57 | ||
|
|
e46bfb136a | ||
|
|
6b214fb577 |
@@ -1,4 +1,5 @@
|
|||||||
[backandup]
|
[backandup]
|
||||||
|
yamllocation=location of docker-compose.yml
|
||||||
bindcludepattern=list of fixed strings
|
bindcludepattern=list of fixed strings
|
||||||
bindexcludepattern=list of fixed strings
|
bindexcludepattern=list of fixed strings
|
||||||
composefile=path to the docker-compose file to parse
|
composefile=path to the docker-compose file to parse
|
||||||
|
|||||||
39
main.py
39
main.py
@@ -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 = False
|
||||||
arguments.dryrun = (parser["restic"]["dryrun"].lower() == "true" or parser["restic"]["dryrun"] > 0)
|
if "dryrun" in parser["restic"] and (parser["restic"]["dryrun"].lower() == "true" \
|
||||||
else:
|
or (parser["restic"]["dryrun"].isdigit() and parser["restic"]["dryrun"] > 0)):
|
||||||
arguments.dryrun = False
|
arguments.dryrun = True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def restic_backup(dirpath: str, tagslist: list = None):
|
def restic_backup(dirpath: str, tagslist: list = None):
|
||||||
@@ -198,10 +199,7 @@ 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:
|
backup_services(dependencie, servicesdict, composefilepath)
|
||||||
continue
|
|
||||||
elif arguments.bindinclude not in ("", None) and dependencie.find(arguments.bindinclude):
|
|
||||||
backup_services(dependencie, servicesdict, composefilepath)
|
|
||||||
|
|
||||||
# TODO: faire la sauvegarde
|
# TODO: faire la sauvegarde
|
||||||
for containerid in containersid:
|
for containerid in containersid:
|
||||||
@@ -209,8 +207,19 @@ 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]
|
||||||
print(f" backup of {bindpath}")
|
if arguments.bindexclude not in ("", None) and bindpath.find(
|
||||||
restic_backup(dirpath=bindpath, tagslist=[servicename])
|
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}")
|
||||||
|
restic_backup(dirpath=bindpath, tagslist=[servicename])
|
||||||
|
|
||||||
for containerindex in range(0, len(containersid)):
|
for containerindex in range(0, len(containersid)):
|
||||||
if containerrunning[containerindex]:
|
if containerrunning[containerindex]:
|
||||||
@@ -222,6 +231,16 @@ def backup_services(servicename: str, servicesdict: dict, composefilepath: str)
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def get_containers_names_and_ids(ymlfile: str) -> list:
|
||||||
|
'''
|
||||||
|
Retrouve les noms et ID des containers contenus dans le fichier yaml. docker-compose les trie
|
||||||
|
par ordre alphabétique par défaut
|
||||||
|
:param ymlfile: str: fichier yaml à parser/utiliser
|
||||||
|
:return: list
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
# Press the green button in the gutter to run the script.
|
# Press the green button in the gutter to run the script.
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
dockerhost = docker.from_env()
|
dockerhost = docker.from_env()
|
||||||
|
|||||||
Reference in New Issue
Block a user