This commit is contained in:
2024-04-03 14:14:28 +02:00
parent 9009140141
commit 50ae5f6325
2 changed files with 17 additions and 8 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "bitlab S3 Backup",
"version": "1.0.9",
"version": "1.0.10",
"slug": "bitlab-s3-backup",
"description": "Sync Backups to bitlab S3 storage",
"url": "https://git.bitlab.ch/bitlab/ha-addon",

View File

@@ -28,6 +28,19 @@ function create-local-backup {
return "${__BASHIO_EXIT_OK}"
}
function delete-s3-backup {
delete_slug=$1
for I in `aws s3api list-objects-v2 --bucket "${bucket_name}" --endpoint-url "${custom_endpoint}" --region "${bucket_region}" --query 'Contents[*].Key' --output text`
do
bashio::log.debug "Checking object: $I"
TAG=`aws s3api get-object-tagging --bucket "${bucket_name}" --endpoint-url "${custom_endpoint}" --region "${bucket_region}" --key "$I" --output text --query "TagSet[?Key=='slug'].Value"`
bashio::log.debug "Slug for object $I: $TAG"
if [ "$TAG" = "$SLUG" ]; then
bashio::log.debug "Deleting object: $I"
aws s3api delete-object --bucket "${bucket_name}" --endpoint-url "${custom_endpoint}" --region "${bucket_region}" --key "$I" --output text
fi
done
}
bashio::log.info "Starting S3 Backup..."
@@ -48,13 +61,8 @@ export AWS_REGION="$bucket_region"
bashio::log.debug "Using AWS CLI version: '$(aws --version)'"
bashio::log.debug "Command: 'aws s3 sync $monitor_path s3://$bucket_name/ --no-progress --region $bucket_region'"
bashio::log.debug "SLUG: $SLUG $BACKUP_NAME"
aws s3 cp "/backup/${SLUG}.tar" "s3://${bucket_name}/${BACKUP_NAME}.tar" --endpoint-url $custom_endpoint --no-progress --region $bucket_region
#aws s3 sync \
# $monitor_path \
# --endpoint-url $custom_endpoint \
# --no-progress \
# s3://$bucket_name/ \
# --region $bucket_region \
aws s3 cp "/backup/${SLUG}.tar" "s3://${bucket_name}/${BACKUP_NAME}.tar" --endpoint-url "${custom_endpoint}" --region "${bucket_region}" --no-progress
aws s3api put-object-tagging --bucket "${bucket_name}" --key "${BACKUP_NAME}.tar" --tagging '{"TagSet": [{ "Key": "slug", "Value": "${SLUG}" }]}' --endpoint-url "${custom_endpoint}" --region "${bucket_region}"
if bashio::var.true "${delete_local_backups}"; then
bashio::log.info "Will delete all the oldest local backups except the '${local_backups_to_keep}' newest ones."
@@ -62,6 +70,7 @@ if bashio::var.true "${delete_local_backups}"; then
bashio::log.debug "Backups to delete: '$backup_slugs'"
for s in $backup_slugs; do
delete-s3-backup "$s"
bashio::log.info "Deleting Backup: '$s'"
bashio::api.supervisor "DELETE" "/backups/$s"
done