-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathrun.sh
executable file
·38 lines (31 loc) · 1.8 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Home Assistant Community Add-on: Amazon S3 Backup
# ==============================================================================
#bashio::log.level "debug"
bashio::log.info "Starting Amazon S3 Backup..."
bucket_name="$(bashio::config 'bucket_name')"
storage_class="$(bashio::config 'storage_class' 'STANDARD')"
bucket_region="$(bashio::config 'bucket_region' 'eu-central-1')"
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 --storage-class $storage_class'"
aws s3 sync $monitor_path s3://"$bucket_name"/ --no-progress --region "$bucket_region" --storage-class "$storage_class"
if bashio::var.true "${delete_local_backups}"; then
bashio::log.info "Will delete 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 Amazon S3 Backup."