remove old get_backup_cmds
This commit is contained in:
		
							
								
								
									
										31
									
								
								backupbot.py
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								backupbot.py
									
									
									
									
									
								
							| @ -208,37 +208,6 @@ def parse_excludes_includes(labels): | ||||
|                 excluded_volumes.add(volume_name) | ||||
|     return excluded_volumes, included_volume_paths | ||||
|  | ||||
| def get_backup_cmds(): | ||||
|     client = docker.from_env() | ||||
|     container_by_service = { | ||||
|         c.labels.get('com.docker.swarm.service.name'): c for c in client.containers.list()} | ||||
|     backup_paths = set() | ||||
|     backup_apps = set() | ||||
|     pre_commands = {} | ||||
|     post_commands = {} | ||||
|     services = client.services.list() | ||||
|     for s in services: | ||||
|         labels = s.attrs['Spec']['Labels'] | ||||
|         if (backup := labels.get('backupbot.backup')) and bool(backup): | ||||
|             # volumes: s.attrs['Spec']['TaskTemplate']['ContainerSpec']['Mounts'][0]['Source'] | ||||
|             stack_name = labels['com.docker.stack.namespace'] | ||||
|             # Remove this lines to backup only a specific service | ||||
|             # This will unfortenately decrease restice performance | ||||
|             # if SERVICE and SERVICE != stack_name: | ||||
|             #     continue | ||||
|             backup_apps.add(stack_name) | ||||
|             backup_paths = backup_paths.union( | ||||
|                 Path(VOLUME_PATH).glob(f"{stack_name}_*")) | ||||
|             if not (container := container_by_service.get(s.name)): | ||||
|                 logger.error( | ||||
|                     f"Container {s.name} is not running, hooks can not be executed") | ||||
|                 continue | ||||
|             if prehook := labels.get('backupbot.backup.pre-hook'): | ||||
|                 pre_commands[container] = prehook | ||||
|             if posthook := labels.get('backupbot.backup.post-hook'): | ||||
|                 post_commands[container] = posthook | ||||
|     return pre_commands, post_commands, list(backup_paths), list(backup_apps) | ||||
|  | ||||
|  | ||||
| def copy_secrets(apps): | ||||
|     # TODO: check if it is deployed | ||||
|  | ||||
		Reference in New Issue
	
	Block a user