forked from coop-cloud/backup-bot-two
		
	Compare commits
	
		
			11 Commits
		
	
	
		
			fix-quotes
			...
			feature/se
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| d998b61117 | |||
| c93d5c6f44 | |||
| 52e52a1e1d | |||
| 771cf31824 | |||
| 83834c6570 | |||
| 98b5f077e2 | |||
| ed687e52c3 | |||
| cf06532da9 | |||
| 319deaba4b | |||
| 3c44300a2e | |||
| 5ac3a48125 | 
							
								
								
									
										21
									
								
								.drone.yml
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								.drone.yml
									
									
									
									
									
								
							| @ -2,11 +2,16 @@ | ||||
| kind: pipeline | ||||
| name: linters | ||||
| steps: | ||||
|   - name: run shellcheck | ||||
|     image: koalaman/shellcheck-alpine | ||||
|     commands: | ||||
|       - shellcheck backup.sh | ||||
|  | ||||
| trigger: | ||||
|   branch: | ||||
|     - main | ||||
|   - name: publish image | ||||
|     image: plugins/docker | ||||
|     settings: | ||||
|       username: 3wordchant | ||||
|       password: | ||||
|         from_secret: git_coopcloud_tech_token_3wc | ||||
|       repo: git.coopcloud.tech/coop-cloud/backup-bot-two | ||||
|       tags: 2.0.0 | ||||
|       registry: git.coopcloud.tech | ||||
|     when: | ||||
|       event: | ||||
|         exclude: | ||||
|           - pull_request | ||||
|  | ||||
							
								
								
									
										10
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,10 @@ | ||||
| FROM docker:24.0.7-dind | ||||
|  | ||||
| RUN apk add --upgrade --no-cache restic bash python3 py3-pip | ||||
|  | ||||
| # Todo use requirements file with specific versions | ||||
| RUN pip install click==8.1.7 docker==6.1.3 resticpy==1.0.2 | ||||
|  | ||||
| COPY backupbot.py /usr/bin/backup | ||||
|  | ||||
| ENTRYPOINT /bin/bash | ||||
| @ -82,7 +82,6 @@ Add your `SSH_KEY` as docker secret: | ||||
| abra app secret insert <app_name> ssh_key v1 """$(cat backupkey) | ||||
| """ | ||||
| ``` | ||||
| > Attention: This command needs to be executed exactly as stated above, because it places a trailing newline at the end, if this is missing you will get the following error: `Load key "/run/secrets/ssh_key": error in libcrypto` | ||||
|  | ||||
| ### Restic REST server Storage | ||||
|  | ||||
|  | ||||
							
								
								
									
										2
									
								
								abra.sh
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								abra.sh
									
									
									
									
									
								
							| @ -1,3 +1,3 @@ | ||||
| export ENTRYPOINT_VERSION=v1 | ||||
| export ENTRYPOINT_VERSION=v2 | ||||
| export BACKUPBOT_VERSION=v1 | ||||
| export SSH_CONFIG_VERSION=v1 | ||||
|  | ||||
							
								
								
									
										15
									
								
								backupbot.py
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								backupbot.py
									
									
									
									
									
								
							| @ -85,6 +85,7 @@ def get_backup_cmds(): | ||||
|     services = client.services.list() | ||||
|     for s in services: | ||||
|         labels = s.attrs['Spec']['Labels'] | ||||
|         mounts = s.attrs['Spec']['TaskTemplate']['ContainerSpec']['Mounts'] | ||||
|         if (backup := labels.get('backupbot.backup')) and bool(backup): | ||||
|             stack_name = labels['com.docker.stack.namespace'] | ||||
|             # Remove this lines to backup only a specific service | ||||
| @ -92,9 +93,15 @@ def get_backup_cmds(): | ||||
|             # 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)): | ||||
|             for mount in mounts: | ||||
|                 if path := labels.get('backupbot.backup.path'): | ||||
|                     path_ = Path(VOLUME_PATH) / f"{mount['Source']}/_data/{path}" | ||||
|                 else: | ||||
|                     path_ = Path(VOLUME_PATH) / f"{mount['Source']}" | ||||
|                 logging.debug( | ||||
|                     f"Added backup path {path_}") | ||||
|                 backup_paths.add(path_) | ||||
|             if not (container := container_by_service.get(s.name)): | ||||
|                 logging.error( | ||||
|                     f"Container {s.name} is not running, hooks can not be executed") | ||||
|                 continue | ||||
| @ -139,7 +146,7 @@ def run_commands(commands): | ||||
|         command = command.removeprefix('bash -c').removeprefix('sh -c') | ||||
|         # Remove quotes surrounding the command | ||||
|         if (len(command) >= 2 and command[0] == command[-1] and (command[0] == "'" or command[0] == '"')): | ||||
|             command = command[1:-1] | ||||
|             command[1:-1] | ||||
|         # Use bash's pipefail to return exit codes inside a pipe to prevent silent failure | ||||
|         command = f"bash -c 'set -o pipefail;{command}'" | ||||
|         logging.info(f"run command in {container.name}:") | ||||
|  | ||||
| @ -2,7 +2,7 @@ | ||||
| version: "3.8" | ||||
| services: | ||||
|   app: | ||||
|     image: docker:24.0.7-dind | ||||
|     image: git.coopcloud.tech/coop-cloud/backup-bot-two:2.0.0 | ||||
|     volumes: | ||||
|       - "/var/run/docker.sock:/var/run/docker.sock" | ||||
|       - "/var/lib/docker/volumes/:/var/lib/docker/volumes/" | ||||
| @ -23,9 +23,6 @@ services: | ||||
|       - source: entrypoint | ||||
|         target: /entrypoint.sh | ||||
|         mode: 0555 | ||||
|       - source: backupbot | ||||
|         target: /usr/bin/backup | ||||
|         mode: 0555 | ||||
|     entrypoint: ['/entrypoint.sh'] | ||||
|     healthcheck: | ||||
|       test: "pgrep crond" | ||||
| @ -46,6 +43,3 @@ configs: | ||||
|   entrypoint: | ||||
|     name: ${STACK_NAME}_entrypoint_${ENTRYPOINT_VERSION} | ||||
|     file: entrypoint.sh | ||||
|   backupbot: | ||||
|     name: ${STACK_NAME}_backupbot_${BACKUPBOT_VERSION} | ||||
|     file: backupbot.py | ||||
|  | ||||
| @ -2,11 +2,6 @@ | ||||
|  | ||||
| set -e -o pipefail | ||||
|  | ||||
| apk add --upgrade --no-cache restic bash python3 py3-pip | ||||
|  | ||||
| # Todo use requirements file with specific versions | ||||
| pip install click==8.1.7 docker==6.1.3 resticpy==1.0.2 | ||||
|  | ||||
| if [ -n "$SSH_HOST_KEY" ] | ||||
| then | ||||
|     echo "$SSH_HOST_KEY" > /root/.ssh/known_hosts | ||||
|  | ||||
		Reference in New Issue
	
	Block a user