forked from coop-cloud/backup-bot-two
		
	Merge pull request 'backup multiple paths' (#5) from multi_path into main
Reviewed-on: coop-cloud/backup-bot-two#5
This commit is contained in:
		| @ -52,11 +52,11 @@ services: | ||||
|         backupbot.backup: "true" | ||||
|         backupbot.backup.pre-hook: 'mysqldump -u root -p"$(cat /run/secrets/db_root_password)" -f /tmp/dump/dump.db' | ||||
|         backupbot.backup.post-hook: "rm -rf /tmp/dump/dump.db" | ||||
|         backupbot.backup.path: "/tmp/dump/" | ||||
|         backupbot.backup.path: "/tmp/dump/,/etc/foo/" | ||||
| ``` | ||||
|  | ||||
| - `backupbot.backup` -- set to `true` to back up this service (REQUIRED) | ||||
| - `backupbot.backup.path` -- file path within the service to copy (REQUIRED) | ||||
| - `backupbot.backup.path` -- comma separated list of file paths within the service to copy (REQUIRED) | ||||
| - `backupbot.backup.pre-hook` -- command to run before copying files (optional) | ||||
| - `backupbot.backup.post-hook` -- command to run after copying files (optional) | ||||
|  | ||||
|  | ||||
							
								
								
									
										17
									
								
								backup.sh
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								backup.sh
									
									
									
									
									
								
							| @ -21,7 +21,7 @@ if [ -n "$ssh_key_file" ] && [ -f "$ssh_key_file" ]; then | ||||
| 	# Only check server against provided SSH_HOST_KEY, if set | ||||
| 	if [ -n "$SSH_HOST_KEY" ]; then | ||||
| 		tmpfile=$(mktemp) | ||||
| 		echo "$SSH_HOST_KEY" >> "$tmpfile" | ||||
| 		echo "$SSH_HOST_KEY" >>"$tmpfile" | ||||
| 		echo "using host key $SSH_HOST_KEY" | ||||
| 		ssh_options="-o 'UserKnownHostsFile $tmpfile'" | ||||
| 	elif [ "$SSH_HOST_KEY_DISABLE" = "1" ]; then | ||||
| @ -72,6 +72,8 @@ else | ||||
| fi | ||||
|  | ||||
| if [[ \ $*\  != *\ --skip-backup\ * ]]; then | ||||
|     rm -rf "${backup_path}" | ||||
|  | ||||
| 	for service in "${services[@]}"; do | ||||
| 		echo "service: $service" | ||||
| 		details=$(docker service inspect "$service" --format "{{ json .Spec.Labels }}") | ||||
| @ -82,13 +84,12 @@ if [[ \ $*\  != *\ --skip-backup\ * ]]; then | ||||
|  | ||||
| 			if [ "$path" = "null" ]; then | ||||
| 				echo "ERROR: missing 'path' for $service" | ||||
| 				continue  # or maybe exit? | ||||
| 				continue # or maybe exit? | ||||
| 			fi | ||||
|  | ||||
| 			container=$(docker container ls -f "name=$service" --format '{{ .ID }}') | ||||
|  | ||||
| 			echo "backing up $service" | ||||
| 			test -d "$backup_path/$service" || mkdir "$backup_path/$service" | ||||
|  | ||||
| 			if [ "$pre" != "null" ]; then | ||||
| 				# run the precommand | ||||
| @ -97,7 +98,12 @@ if [[ \ $*\  != *\ --skip-backup\ * ]]; then | ||||
| 			fi | ||||
|  | ||||
| 			# run the backup | ||||
| 			docker cp "$container:$path" "$backup_path/$service" | ||||
| 			for p in ${path//,/ }; do | ||||
| 				# creates the parent folder, so `docker cp` has reliable behaviour no matter if $p ends with `/` or `/.` | ||||
| 				dir=$backup_path/$service/$(dirname "$p") | ||||
| 				test -d "$dir" || mkdir -p "$dir" | ||||
| 				docker cp -a "$container:$p" "$dir/$(basename "$p")" | ||||
| 			done | ||||
|  | ||||
| 			if [ "$post" != "null" ]; then | ||||
| 				# run the postcommand | ||||
| @ -115,5 +121,6 @@ if [[ \ $*\  != *\ --skip-backup\ * ]]; then | ||||
| fi | ||||
|  | ||||
| if [[ \ $*\  != *\ --skip-upload\ * ]]; then | ||||
| 	_restic backup --tag coop-cloud "$backup_path" | ||||
| 	_restic backup --host "$server_name" --tag coop-cloud "$backup_path" | ||||
| fi | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user