run.sh
This commit is contained in:
44
amazon-s3-backup/run.sh
Executable file
44
amazon-s3-backup/run.sh
Executable file
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
# ==============================================================================
|
||||
# Home Assistant Community Add-on: S3 Backup
|
||||
# ==============================================================================
|
||||
#bashio::log.level "info"
|
||||
|
||||
bashio::log.info "Starting S3 Backup..."
|
||||
|
||||
custom_endpoint="$(bashio::config 'custom_endpoint')"
|
||||
bucket_name="$(bashio::config 'bucket_name')"
|
||||
bucket_region="$(bashio::config 'bucket_region' 'minio')"
|
||||
delete_local_backups="$(bashio::config 'delete_local_backups' 'true')"
|
||||
local_backups_to_keep="$(bashio::config 'local_backups_to_keep' '3')"
|
||||
monitor_path="/backup"
|
||||
jq_filter=".backups|=sort_by(.date)|.backups|reverse|.[$local_backups_to_keep:]|.[].slug"
|
||||
|
||||
export AWS_ACCESS_KEY_ID="$(bashio::config 'aws_access_key')"
|
||||
export AWS_SECRET_ACCESS_KEY="$(bashio::config 'aws_secret_access_key')"
|
||||
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'"
|
||||
|
||||
aws s3 sync \
|
||||
$monitor_path \
|
||||
--endpoint-url $custom_endpoint \
|
||||
s3://$bucket_name/ \
|
||||
--no-progress \
|
||||
--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."
|
||||
backup_slugs="$(bashio::api.supervisor "GET" "/backups" "false" $jq_filter)"
|
||||
bashio::log.debug "Backups to delete: '$backup_slugs'"
|
||||
|
||||
for s in $backup_slugs; do
|
||||
bashio::log.info "Deleting Backup: '$s'"
|
||||
bashio::api.supervisor "DELETE" "/backups/$s"
|
||||
done
|
||||
else
|
||||
bashio::log.info "Will not delete any local backups since 'delete_local_backups' is set to 'false'"
|
||||
fi
|
||||
|
||||
bashio::log.info "Finished S3 Backup."
|
||||
Reference in New Issue
Block a user