will it blend?
This commit is contained in:
41
main.py
41
main.py
@@ -146,6 +146,44 @@ def order_services_by_dependencies(servicesdict: dict) -> list:
|
||||
return serviceslist
|
||||
|
||||
|
||||
def backup_service(servicename: str, servicesdict: dict, composefilepath: str) -> bool:
|
||||
'''
|
||||
Pause les containers, lance la backup des dépendances si il y en a, lance sa propre backup,
|
||||
puis redémarre les containers.
|
||||
:param servicename: str
|
||||
:param servicesdict: dict
|
||||
:return: bool
|
||||
'''
|
||||
|
||||
if servicesdict[servicename]["backupdone"]:
|
||||
return True
|
||||
|
||||
dockerclient = docker.from_env()
|
||||
containersid = os.popen(f"docker-compose --file {composefilepath} ps --quiet {servicename}").readlines()
|
||||
containerrunning = []
|
||||
for containerid in containersid:
|
||||
container = dockerclient.containers.get(containerid)
|
||||
containerrunning.append(container.status == "running")
|
||||
print(f"stopping {container.name}")
|
||||
container.stop()
|
||||
|
||||
if len(servicesdict[servicename]["must_before"]):
|
||||
for dependencie in servicesdict[servicename]["must_before"]:
|
||||
backup_service(dependencie, servicesdict, composefilepath)
|
||||
|
||||
# TODO: faire la sauvegarde
|
||||
print(f"starting backup")
|
||||
|
||||
for containerindex in range(0, len(containersid)):
|
||||
if containerrunning[containerindex]:
|
||||
container = dockerclient.containers.get(containersid[containerindex])
|
||||
print(f"restarting {container.name}")
|
||||
container.start()
|
||||
|
||||
servicesdict[servicename]["backupdone"] = True
|
||||
return True
|
||||
|
||||
|
||||
def yaml_file_to_container_list(filepath: str) -> list|None:
|
||||
'''
|
||||
Retourne le contenu d'un fichier yaml sous forme de dictionnaire
|
||||
@@ -204,4 +242,5 @@ if __name__ == '__main__':
|
||||
|
||||
servicesDict = yaml_to_services_list(composefile)
|
||||
servicesList = order_services_by_dependencies(servicesDict)
|
||||
print(servicesList)
|
||||
for servicetobackup in reversed(servicesList):
|
||||
backup_service(servicetobackup)
|
||||
|
||||
Reference in New Issue
Block a user