fix docker cp paths
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Philipp Rothmann 2021-11-24 11:17:13 +01:00
parent f2472bd0d3
commit ce42fb06fd
1 changed files with 11 additions and 8 deletions

View File

@ -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
@ -79,27 +79,28 @@ if [[ \ $*\ != *\ --skip-backup\ * ]]; then
pre=$(echo "$details" | jq -r '.["backupbot.backup.pre-hook"]')
post=$(echo "$details" | jq -r '.["backupbot.backup.post-hook"]')
path=$(echo "$details" | jq -r '.["backupbot.backup.path"]')
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"
if [ "$pre" != "null" ]; then
# run the precommand
# shellcheck disable=SC2086
docker exec "$container" sh -c "$pre"
fi
test -d "$backup_path/$service" || mkdir -p "$backup_path/$service"
# run the backup
for p in ${path//,/ }; do
docker cp "$container:$p" "$backup_path/$service"
# 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 "$container:$p" "$dir/$(basename "$p")"
done
if [ "$post" != "null" ]; then
@ -120,3 +121,5 @@ fi
if [[ \ $*\ != *\ --skip-upload\ * ]]; then
_restic backup --host "$server_name" --tag coop-cloud "$backup_path"
fi
rm -rf "${backup_path}"