Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize s3-backup #5

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions amazon-s3-backup/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.3.0

- Add an endpoint_url config
- If set, this url will used as s3 api endpoint

## 1.2.2

- Backup Script was running twice since it was still in services.d folder. Removed all unnecessary files.
Expand Down
3 changes: 3 additions & 0 deletions amazon-s3-backup/DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ AWS IAM access key used to access the S3 bucket.
### Option: `aws_secret_access_key` (required)
AWS IAM secret access key used to access the S3 bucket.

### Option: `max_concurrent_requests` (optional, Default: 10)
Set how many uploads are done in parallel.

### Option: `bucket_name` (required)
Amazon S3 bucket used to store backups.

Expand Down
8 changes: 6 additions & 2 deletions amazon-s3-backup/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Amazon S3 Backup",
"version": "1.2.2",
"version": "1.3.0",
"slug": "amazon-s3-backup",
"description": "Sync Backups to your Amazon S3 bucket",
"url": "https://github.com/thomasfr/hass-addons/tree/main/amazon-s3-backup",
Expand All @@ -20,6 +20,8 @@
"options": {
"aws_access_key": "",
"aws_secret_access_key": "",
"endpoint_url": "",
"max_concurrent_requests": 10,
"bucket_name": "",
"bucket_region": "eu-central-1",
"storage_class": "STANDARD",
Expand All @@ -29,8 +31,10 @@
"schema": {
"aws_access_key": "str",
"aws_secret_access_key": "password",
"endpoint_url": "str",
"max_concurrent_requests": "int",
"bucket_name": "str",
"bucket_region": "list(us-east-1|us-east-2|us-west-1|us-west-2|af-south-1|ap-east-1|ap-south-2|ap-southeast-3|ap-southeast-4|ap-south-1|ap-northeast-3|ap-northeast-2|ap-southeast-1|ap-southeast-2|ap-northeast-1|ca-central-1|eu-central-1|eu-west-1|eu-west-2|eu-south-1|eu-west-3|eu-south-2|eu-north-1|eu-central-2|me-south-1|me-central-1|sa-east-1|us-gov-east-1|us-gov-west-1)",
"bucket_region": "str",
"storage_class": "list(STANDARD|REDUCED_REDUNDANCY|STANDARD_IA|ONEZONE_IA|INTELLIGENT_TIERING|GLACIER|DEEP_ARCHIVE)",
"delete_local_backups": "bool",
"local_backups_to_keep": "int"
Expand Down
24 changes: 18 additions & 6 deletions amazon-s3-backup/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,32 @@
# ==============================================================================
#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.info "Configure S3 Backup..."
aws configure set aws_access_key_id "$(bashio::config 'aws_access_key')"
aws configure set aws_secret_access_key "$(bashio::config 'aws_secret_access_key')"

aws configure set plugins.endpoint awscli_plugin_endpoint
if bashio::config.has_value "endpoint_url"; then
endpoint_url="$(bashio::config 'endpoint_url' '')"
bashio::log.info "Configure Amazon S3 Backup endpoint to ${endpoint_url}"
aws configure set s3.endpoint_url "${endpoint_url}"
aws configure set s3api.endpoint_url "${endpoint_url}"
fi

if bashio::config.has_value "max_concurrent_requests"; then
aws configure set s3.max_concurrent_requests "$(bashio::config 'max_concurrent_requests' '10')"
fi

aws configure set region "$(bashio::config 'bucket_region' 'eu-central-1')"

bashio::log.info "Starting Amazon S3 Backup..."
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"
Expand Down