From caaa607e9445534e51cb4a2feb6c4c9f33c4e886 Mon Sep 17 00:00:00 2001 From: Tibo De Peuter Date: Sun, 23 Nov 2025 15:26:25 +0100 Subject: [PATCH] fix: file changed as tar read it --- scripts/gitea/backup-database-ssh.sh | 10 ++++++---- scripts/nextcloud/backup-database-ssh.sh | 12 +++++++----- scripts/vaultwarden/backup-database-ssh.sh | 10 ++++++---- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/scripts/gitea/backup-database-ssh.sh b/scripts/gitea/backup-database-ssh.sh index 3c8673e..d161c7c 100755 --- a/scripts/gitea/backup-database-ssh.sh +++ b/scripts/gitea/backup-database-ssh.sh @@ -106,12 +106,14 @@ ssh "${remote}" "docker exec --env-file '${env_file}' '${database_container}' pg # TODO # Copy everything over to local machine. +echo 'Info: Creating archive' +remote_archive="$( ssh "${remote}" 'mktemp' )" +ssh "${remote}" "tar -czf '${remote_archive}' ${remote_destination}" echo 'Info: Copying to local machine.' -ssh "${remote}" "tar -czf '/tmp/${backupfile}' ${remote_destination}" -scp "${remote}:/tmp/${backupfile}" "${local_destination}" +scp "${remote}:${remote_archive}" "${local_destination}/${backupfile}" # Remove temporary destination on remote host. -printf "Debug: Cleaning up '%s' on %s.\n" "${remote_destination}" "${remote}" -ssh "${remote}" "rm -rf ${remote_destination}" +printf "Debug: Cleaning up '%s' on %s.\n" "${remote_destination},${remote_archive}" "${remote}" +ssh "${remote}" "rm -rf ${remote_destination} ${remote_archive}" echo 'Done' diff --git a/scripts/nextcloud/backup-database-ssh.sh b/scripts/nextcloud/backup-database-ssh.sh index 9e2a705..6479967 100755 --- a/scripts/nextcloud/backup-database-ssh.sh +++ b/scripts/nextcloud/backup-database-ssh.sh @@ -47,8 +47,8 @@ set -e if ! ssh "${remote}" "test -f '${env_file:=.env}'"; then >&2 printf "Error: Environment file does not exist: '%s'.\n" "${env_file}" - >&2 printf "Debug: PWD: '%s'.\n" "$(ssh "${remote}" 'pwd')" >&2 printf " Consider using the option '-e' to specify the correct environment file.\n" + >&2 printf "Debug: PWD: '%s'.\n" "$(ssh "${remote}" 'pwd')" usage 2 elif ! ssh "${remote}" "test -r '${env_file:=.env}'"; then >&2 printf "Error: Environment file is not readable: '%s'.\n" "${env_file}" @@ -96,13 +96,15 @@ ssh "${remote}" "cp -a '/var/www/nextcloud/themes' '${remote_destination}'" ssh "${remote}" 'sudo -u www-data /usr/bin/php /var/www/nextcloud/occ maintenance:mode --off' # Copy everything over to local machine. +echo 'Info: Creating archive' +remote_archive="$( ssh "${remote}" 'mktemp' )" +ssh "${remote}" "tar -czf '${remote_archive}' ${remote_destination}" echo 'Info: Copying to local machine.' -ssh "${remote}" "tar -czf '/tmp/${backupfile}' ${remote_destination}" -scp "${remote}:/tmp/${backupfile}" "${local_destination}" +scp "${remote}:${remote_archive}" "${local_destination}/${backupfile}" # Remove temporary destination on remote host. -printf "Debug: Cleaning up '%s' on %s.\n" "${remote_destination}" "${remote}" -ssh "${remote}" "rm -rf ${remote_destination}" +printf "Debug: Cleaning up '%s' on %s.\n" "${remote_destination},${remote_archive}" "${remote}" +ssh "${remote}" "rm -rf ${remote_destination} ${remote_archive}" # Backup cleanup # Only keep 30 days of backups diff --git a/scripts/vaultwarden/backup-database-ssh.sh b/scripts/vaultwarden/backup-database-ssh.sh index c348c36..994bd2f 100755 --- a/scripts/vaultwarden/backup-database-ssh.sh +++ b/scripts/vaultwarden/backup-database-ssh.sh @@ -97,13 +97,15 @@ for file in 'attachments' 'sends' 'rsa_key.pem' 'rsa_key.pub.pem'; do # 'config done # Copy everything over to local machine. +echo 'Info: Creating archive' +remote_archive="$( ssh "${remote}" 'mktemp' )" +ssh "${remote}" "tar -czf '${remote_archive}' ${remote_destination}" echo 'Info: Copying to local machine.' -ssh "${remote}" "tar -czf '${remote_destination}/${backupfile}' --exclude=${backupfile} ${remote_destination}" -scp "${remote}:${remote_destination}/${backupfile}" "${local_destination}" +scp "${remote}:${remote_archive}" "${local_destination}/${backupfile}" # Remove temporary destination on remote host. -printf "Debug: Cleaning up '%s' on %s.\n" "${remote_destination}" "${remote}" -ssh "${remote}" "rm -rf ${remote_destination}" +printf "Debug: Cleaning up '%s' on %s.\n" "${remote_destination},${remote_archive}" "${remote}" +ssh "${remote}" "rm -rf ${remote_destination} ${remote_archive}" # Backup cleanup # Only keep 30 days of backups, seems about right.