More progress towards S3/SSH

This commit is contained in:
3wc 2021-11-09 14:20:11 +02:00
parent ed76e6164b
commit 23b092776f
2 changed files with 38 additions and 6 deletions

View File

@ -4,9 +4,37 @@ server_name="${SERVER_NAME:?SERVER_NAME not set}"
restic_password_file="${RESTIC_PASSWORD_FILE:?RESTIC_PASSWORD_FILE not set}"
restic_sftp_host="${RESTIC_SFTP_HOST:?RESTIC_SFTP_HOST not set}"
restic_host="${RESTIC_HOST:?RESTIC_HOST not set}"
restic_repo="sftp:$restic_sftp_host:/$server_name"
ssh_key_file="${SSH_KEY_FILE}"
s3_key_file="${AWS_SECRET_ACCESS_KEY_FILE}"
restic_repo=
restic_extra_options=
if [ -n "$ssh_key_file" ] && [ -f "$ssh_key_file" ]; then
restic_repo="sftp:$restic_host:/$server_name"
restic_extra_options="sftp.command=ssh -i $ssh_key_file $restic_host -s sftp"
fi
if [ -n "$s3_key_file" ] && [ -f "$s3_key_file" ]; then
export "$AWS_SECRET_ACCESS_KEY"="$(cat "${s3_key_file}")"
restic_repo="s3:$restic_host:/$server_name"
fi
if [ -z "$restic_repo" ]; then
echo "You must configure either SFTP or S3 storage"
exit 1
fi
# Pre-bake-in some default restic options
_restic() {
# shellcheck disable=SC2068
restic -p "$restic_password_file" \
--quiet -r "$restic_repo" \
"${restic_extra_options:+-o}" "$restic_extra_options" \
$@
}
backup_path="${BACKUP_DEST:?BACKUP_DEST not set}"
@ -54,7 +82,10 @@ for service in "${services[@]}"; do
fi
done
restic -p "$restic_password_file" \
backup --quiet -r "$restic_repo" \
-o sftp.command="ssh $restic_sftp_host -s sftp" \
--tag coop-cloud "$backup_path"
# Check if restic repo exists
if [ -z "$(_restic cat config)" ] 2>/dev/null; then
echo "initializing restic repo"
_restic init
fi
_restic backup --tag coop-cloud "$backup_path"

View File

@ -11,6 +11,7 @@ services:
- RESTIC_REPO
- RESTIC_PASSWORD_FILE=/run/secrets/restic_password
- BACKUP_DEST=/backups
- RESTIC_HOST
- SERVER_NAME
secrets:
- restic_password