diff --git a/Readme.md b/Readme.md index 5bed15e..ebf7b81 100644 --- a/Readme.md +++ b/Readme.md @@ -37,13 +37,17 @@ Role Variables | backup_compression_enabled | yes | `true` | bool | Wether or not to compress the archive file | | backup_compressor | yes | `gzip` | string | | | backup_compression_level | yes | `1` | int | | +| backup_aws_command | yes | `aws` | string | | | backup_aws_upload_enabled | yes | `false` | bool | | | backup_aws_bucket_name | yes | `mybucket` | string | | | backup_aws_region | yes | `us-east-1` | string | | +| backup_gcloud_command | yes | `gsutil` | string | | | backup_gcloud_upload_enabled | yes | `false` | bool | | | backup_gcloud_bucket_name | yes | `mybucket` | string | | +| backup_b2_command | yes | `b2` | string | | | backup_b2_upload_enabled | yes | `false` | bool | Enable Backblaze B2 upload. | | backup_b2_bucket_name | yes | `mybucket` | string | Backblaze B2 bucket name. | +| backup_restic_command | yes | `restic` | string | | | backup_restic_enabled | yes | `false` | bool | | | backup_restic_forget_options | yes | `--keep-daily 90 --prune` | string | See (all options)[https://restic.readthedocs.io/en/latest/060_forget.html#removing-snapshots-according-to-a-policy]. | | backup_restic_check_enabled | yes | `false` | bool | | diff --git a/defaults/main.yml b/defaults/main.yml index e945d3f..4c51e02 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -36,16 +36,20 @@ backup_compression_enabled: true backup_compressor: gzip backup_compression_level: 1 +backup_aws_command: aws backup_aws_upload_enabled: false backup_aws_bucket_name: mybucket backup_aws_region: us-east-1 +backup_gcloud_command: gsutil backup_gcloud_upload_enabled: false backup_gcloud_bucket_name: mybucket +backup_b2_path: b2 backup_b2_upload_enabled: false backup_b2_bucket_name: mybucket +backup_restic_command: restic backup_restic_enabled: false backup_restic_forget_options: --keep-daily 90 --prune backup_restic_check_enabled: false diff --git a/templates/docker_mariabackup.sh.j2 b/templates/docker_mariabackup.sh.j2 index d09ad97..ffc4ac8 100644 --- a/templates/docker_mariabackup.sh.j2 +++ b/templates/docker_mariabackup.sh.j2 @@ -101,7 +101,7 @@ upload() { {% if item.vars.aws_upload_enabled | d(backup_aws_upload_enabled) %} echo "Uploading to AWS..." - aws s3 --region {{ backup_aws_region }} \ + {{ backup_aws_command }} s3 --region {{ backup_aws_region }} \ cp --only-show-errors \ ${DEST_FILE} s3://{{ backup_aws_bucket_name }}/${SERVICE}/ {% endif %} @@ -109,13 +109,13 @@ upload() { {% if item.vars.gcloud_upload_enabled | d(backup_gcloud_upload_enabled) %} echo "Uploading to GCloud..." - gsutil -q cp ${DEST_FILE} gs://{{ backup_gcloud_bucket_name }}/${SERVICE}/ + {{ backup_gcloud_command }} -q cp ${DEST_FILE} gs://{{ backup_gcloud_bucket_name }}/${SERVICE}/ {% endif %} {% if item.vars.b2_upload_enabled | d(backup_b2_upload_enabled) %} echo "Uploading to Backblaze B2..." - b2 upload-file \ + {{ backup_b2_path }} upload-file \ --quiet \ --noProgress \ {{ backup_b2_bucket_name }} \ @@ -125,20 +125,20 @@ upload() { {% endif %} {% if item.vars.restic_enabled | d(backup_restic_enabled) %} - restic --quiet snapshots > /dev/null || restic --quiet init + {{ backup_restic_command }} --quiet snapshots > /dev/null || {{ backup_restic_command }} --quiet init echo "Performing backup through restic..." - restic --quiet backup ${DEST_DIR} --tag ${SERVICE} + {{ backup_restic_command }} --quiet backup ${DEST_DIR} --tag ${SERVICE} echo "Forgetting old restic snapshots..." - restic --quiet forget --tag ${SERVICE} {{ backup_restic_forget_options }} + {{ backup_restic_command }} --quiet forget --tag ${SERVICE} {{ backup_restic_forget_options }} {% if item.vars.restic_check_enabled | d(backup_restic_check_enabled) %} echo "Checking restic data..." - restic --quiet check + {{ backup_restic_command }} --quiet check {% endif %} {% endif %} } diff --git a/templates/files.sh.j2 b/templates/files.sh.j2 index 113e990..4d583c0 100644 --- a/templates/files.sh.j2 +++ b/templates/files.sh.j2 @@ -63,7 +63,7 @@ upload() { {% if item.vars.aws_upload_enabled | d(backup_aws_upload_enabled) %} echo "Uploading to AWS..." - aws s3 --region {{ backup_aws_region }} \ + {{ backup_aws_command }} s3 --region {{ backup_aws_region }} \ cp --only-show-errors \ ${DEST_FILE} s3://{{ backup_aws_bucket_name }}/${SERVICE}/ {% endif %} @@ -71,13 +71,13 @@ upload() { {% if item.vars.gcloud_upload_enabled | d(backup_gcloud_upload_enabled) %} echo "Uploading to GCloud..." - gsutil -q cp ${DEST_FILE} gs://{{ backup_gcloud_bucket_name }}/${SERVICE}/ + {{ backup_gcloud_command }} -q cp ${DEST_FILE} gs://{{ backup_gcloud_bucket_name }}/${SERVICE}/ {% endif %} {% if item.vars.b2_upload_enabled | d(backup_b2_upload_enabled) %} echo "Uploading to Backblaze B2..." - b2 upload-file \ + {{ backup_b2_path }} upload-file \ --quiet \ --noProgress \ {{ backup_b2_bucket_name }} \ @@ -87,20 +87,20 @@ upload() { {% endif %} {% if item.vars.restic_enabled | d(backup_restic_enabled) %} - restic --quiet snapshots > /dev/null || restic --quiet init + {{ backup_restic_command }} --quiet snapshots > /dev/null || {{ backup_restic_command }} --quiet init echo "Performing backup through restic..." - restic --quiet backup ${FILES_PATH} --tag ${SERVICE} + {{ backup_restic_command }} --quiet backup ${FILES_PATH} --tag ${SERVICE} echo "Forgetting old restic snapshots..." - restic --quiet forget --tag ${SERVICE} {{ backup_restic_forget_options }} + {{ backup_restic_command }} --quiet forget --tag ${SERVICE} {{ backup_restic_forget_options }} {% if item.vars.restic_check_enabled | d(backup_restic_check_enabled) %} echo "Checking restic data..." - restic --quiet check + {{ backup_restic_command }} --quiet check {% endif %} {% endif %} } diff --git a/templates/influxdb.sh.j2 b/templates/influxdb.sh.j2 index b383351..f92b47a 100644 --- a/templates/influxdb.sh.j2 +++ b/templates/influxdb.sh.j2 @@ -74,7 +74,7 @@ upload() { {% if item.vars.aws_upload_enabled | d(backup_aws_upload_enabled) %} echo "Uploading to AWS..." - aws s3 --region {{ backup_aws_region }} \ + {{ backup_aws_command }} s3 --region {{ backup_aws_region }} \ cp --only-show-errors \ ${DEST_FILE} s3://{{ backup_aws_bucket_name }}/${SERVICE}/ {% endif %} @@ -82,13 +82,13 @@ upload() { {% if item.vars.gcloud_upload_enabled | d(backup_gcloud_upload_enabled) %} echo "Uploading to GCloud..." - gsutil -q cp ${DEST_FILE} gs://{{ backup_gcloud_bucket_name }}/${SERVICE}/ + {{ backup_gcloud_command }} -q cp ${DEST_FILE} gs://{{ backup_gcloud_bucket_name }}/${SERVICE}/ {% endif %} {% if item.vars.b2_upload_enabled | d(backup_b2_upload_enabled) %} echo "Uploading to Backblaze B2..." - b2 upload-file \ + {{ backup_b2_path }} upload-file \ --quiet \ --noProgress \ {{ backup_b2_bucket_name }} \ @@ -98,20 +98,20 @@ upload() { {% endif %} {% if item.vars.restic_enabled | d(backup_restic_enabled) %} - restic --quiet snapshots > /dev/null || restic --quiet init + {{ backup_restic_command }} --quiet snapshots > /dev/null || {{ backup_restic_command }} --quiet init echo "Performing backup through restic..." - restic --quiet backup ${DEST_DIR} --tag ${SERVICE} + {{ backup_restic_command }} --quiet backup ${DEST_DIR} --tag ${SERVICE} echo "Forgetting old restic snapshots..." - restic --quiet forget --tag ${SERVICE} {{ backup_restic_forget_options }} + {{ backup_restic_command }} --quiet forget --tag ${SERVICE} {{ backup_restic_forget_options }} {% if item.vars.restic_check_enabled | d(backup_restic_check_enabled) %} echo "Checking restic data..." - restic --quiet check + {{ backup_restic_command }} --quiet check {% endif %} {% endif %} } diff --git a/templates/mongodump.sh.j2 b/templates/mongodump.sh.j2 index cffd236..366bea1 100644 --- a/templates/mongodump.sh.j2 +++ b/templates/mongodump.sh.j2 @@ -76,7 +76,7 @@ upload() { {% if item.vars.aws_upload_enabled | d(backup_aws_upload_enabled) %} echo "Uploading to AWS..." - aws s3 --region {{ backup_aws_region }} \ + {{ backup_aws_command }} s3 --region {{ backup_aws_region }} \ cp --only-show-errors \ ${DEST_FILE} s3://{{ backup_aws_bucket_name }}/${SERVICE}/ {% endif %} @@ -84,13 +84,13 @@ upload() { {% if item.vars.gcloud_upload_enabled | d(backup_gcloud_upload_enabled) %} echo "Uploading to GCloud..." - gsutil -q cp ${DEST_FILE} gs://{{ backup_gcloud_bucket_name }}/${SERVICE}/ + {{ backup_gcloud_command }} -q cp ${DEST_FILE} gs://{{ backup_gcloud_bucket_name }}/${SERVICE}/ {% endif %} {% if item.vars.b2_upload_enabled | d(backup_b2_upload_enabled) %} echo "Uploading to Backblaze B2..." - b2 upload-file \ + {{ backup_b2_path }} upload-file \ --quiet \ --noProgress \ {{ backup_b2_bucket_name }} \ @@ -100,20 +100,20 @@ upload() { {% endif %} {% if item.vars.restic_enabled | d(backup_restic_enabled) %} - restic --quiet snapshots > /dev/null || restic --quiet init + {{ backup_restic_command }} --quiet snapshots > /dev/null || {{ backup_restic_command }} --quiet init echo "Performing backup through restic..." - restic --quiet backup ${DEST_DIR} --tag ${SERVICE} + {{ backup_restic_command }} --quiet backup ${DEST_DIR} --tag ${SERVICE} echo "Forgetting old restic snapshots..." - restic --quiet forget --tag ${SERVICE} {{ backup_restic_forget_options }} + {{ backup_restic_command }} --quiet forget --tag ${SERVICE} {{ backup_restic_forget_options }} {% if item.vars.restic_check_enabled | d(backup_restic_check_enabled) %} echo "Checking restic data..." - restic --quiet check + {{ backup_restic_command }} --quiet check {% endif %} {% endif %} } diff --git a/templates/mysqldump.sh.j2 b/templates/mysqldump.sh.j2 index bf7b6d0..fe6d83c 100644 --- a/templates/mysqldump.sh.j2 +++ b/templates/mysqldump.sh.j2 @@ -78,7 +78,7 @@ upload() { {% if item.vars.aws_upload_enabled | d(backup_aws_upload_enabled) %} echo "Uploading to AWS..." - aws s3 --region {{ backup_aws_region }} \ + {{ backup_aws_command }} s3 --region {{ backup_aws_region }} \ cp --only-show-errors \ ${DEST_FILE} s3://{{ backup_aws_bucket_name }}/${SERVICE}/ {% endif %} @@ -86,13 +86,13 @@ upload() { {% if item.vars.gcloud_upload_enabled | d(backup_gcloud_upload_enabled) %} echo "Uploading to GCloud..." - gsutil -q cp ${DEST_FILE} gs://{{ backup_gcloud_bucket_name }}/${SERVICE}/ + {{ backup_gcloud_command }} -q cp ${DEST_FILE} gs://{{ backup_gcloud_bucket_name }}/${SERVICE}/ {% endif %} {% if item.vars.b2_upload_enabled | d(backup_b2_upload_enabled) %} echo "Uploading to Backblaze B2..." - b2 upload-file \ + {{ backup_b2_path }} upload-file \ --quiet \ --noProgress \ {{ backup_b2_bucket_name }} \ @@ -102,20 +102,20 @@ upload() { {% endif %} {% if item.vars.restic_enabled | d(backup_restic_enabled) %} - restic --quiet snapshots > /dev/null || restic --quiet init + {{ backup_restic_command }} --quiet snapshots > /dev/null || {{ backup_restic_command }} --quiet init echo "Performing backup through restic..." - restic --quiet backup ${DEST_DIR} --tag ${SERVICE} + {{ backup_restic_command }} --quiet backup ${DEST_DIR} --tag ${SERVICE} echo "Forgetting old restic snapshots..." - restic --quiet forget --tag ${SERVICE} {{ backup_restic_forget_options }} + {{ backup_restic_command }} --quiet forget --tag ${SERVICE} {{ backup_restic_forget_options }} {% if item.vars.restic_check_enabled | d(backup_restic_check_enabled) %} echo "Checking restic data..." - restic --quiet check + {{ backup_restic_command }} --quiet check {% endif %} {% endif %} } diff --git a/templates/s3_bucket.sh.j2 b/templates/s3_bucket.sh.j2 index 05f344e..c6621b4 100644 --- a/templates/s3_bucket.sh.j2 +++ b/templates/s3_bucket.sh.j2 @@ -39,7 +39,7 @@ prepare() { echo "Syncing remote bucket with local copy..." - aws s3 sync --delete \ + {{ backup_aws_command }} s3 sync --delete \ --only-show-errors \ {{ item.vars.s3_sync_options | d('') }} \ s3://${BUCKET_NAME}/ ${S3_SYNC_PATH}/ @@ -71,7 +71,7 @@ upload() { {% if item.vars.aws_upload_enabled | d(backup_aws_upload_enabled) %} echo "Uploading to AWS..." - aws s3 --region {{ backup_aws_region }} \ + {{ backup_aws_command }} s3 --region {{ backup_aws_region }} \ cp --only-show-errors \ ${DEST_FILE} s3://{{ backup_aws_bucket_name }}/${SERVICE}/ {% endif %} @@ -79,13 +79,13 @@ upload() { {% if item.vars.gcloud_upload_enabled | d(backup_gcloud_upload_enabled) %} echo "Uploading to GCloud..." - gsutil -q cp ${DEST_FILE} gs://{{ backup_gcloud_bucket_name }}/${SERVICE}/ + {{ backup_gcloud_command }} -q cp ${DEST_FILE} gs://{{ backup_gcloud_bucket_name }}/${SERVICE}/ {% endif %} {% if item.vars.b2_upload_enabled | d(backup_b2_upload_enabled) %} echo "Uploading to Backblaze B2..." - b2 upload-file \ + {{ backup_b2_path }} upload-file \ --quiet \ --noProgress \ {{ backup_b2_bucket_name }} \ @@ -95,20 +95,20 @@ upload() { {% endif %} {% if item.vars.restic_enabled | d(backup_restic_enabled) %} - restic --quiet snapshots > /dev/null || restic --quiet init + {{ backup_restic_command }} --quiet snapshots > /dev/null || {{ backup_restic_command }} --quiet init echo "Performing backup through restic..." - restic --quiet backup ${S3_SYNC_PATH} --tag ${SERVICE} + {{ backup_restic_command }} --quiet backup ${S3_SYNC_PATH} --tag ${SERVICE} echo "Forgetting old restic snapshots..." - restic --quiet forget --tag ${SERVICE} {{ backup_restic_forget_options }} + {{ backup_restic_command }} --quiet forget --tag ${SERVICE} {{ backup_restic_forget_options }} {% if item.vars.restic_check_enabled | d(backup_restic_check_enabled) %} echo "Checking restic data..." - restic --quiet check + {{ backup_restic_command }} --quiet check {% endif %} {% endif %} } diff --git a/templates/xtrabackup.sh.j2 b/templates/xtrabackup.sh.j2 index 787c843..217ac7f 100644 --- a/templates/xtrabackup.sh.j2 +++ b/templates/xtrabackup.sh.j2 @@ -82,7 +82,7 @@ upload() { {% if item.vars.aws_upload_enabled | d(backup_aws_upload_enabled) %} echo "Uploading to AWS..." - aws s3 --region {{ backup_aws_region }} \ + {{ backup_aws_command }} s3 --region {{ backup_aws_region }} \ cp --only-show-errors \ ${DEST_FILE} s3://{{ backup_aws_bucket_name }}/${SERVICE}/ {% endif %} @@ -90,13 +90,13 @@ upload() { {% if item.vars.gcloud_upload_enabled | d(backup_gcloud_upload_enabled) %} echo "Uploading to GCloud..." - gsutil -q cp ${DEST_FILE} gs://{{ backup_gcloud_bucket_name }}/${SERVICE}/ + {{ backup_gcloud_command }} -q cp ${DEST_FILE} gs://{{ backup_gcloud_bucket_name }}/${SERVICE}/ {% endif %} {% if item.vars.b2_upload_enabled | d(backup_b2_upload_enabled) %} echo "Uploading to Backblaze B2..." - b2 upload-file \ + {{ backup_b2_path }} upload-file \ --quiet \ --noProgress \ {{ backup_b2_bucket_name }} \ @@ -106,20 +106,20 @@ upload() { {% endif %} {% if item.vars.restic_enabled | d(backup_restic_enabled) %} - restic --quiet snapshots > /dev/null || restic --quiet init + {{ backup_restic_command }} --quiet snapshots > /dev/null || {{ backup_restic_command }} --quiet init echo "Performing backup through restic..." - restic --quiet backup ${DEST_DIR} --tag ${SERVICE} + {{ backup_restic_command }} --quiet backup ${DEST_DIR} --tag ${SERVICE} echo "Forgetting old restic snapshots..." - restic --quiet forget --tag ${SERVICE} {{ backup_restic_forget_options }} + {{ backup_restic_command }} --quiet forget --tag ${SERVICE} {{ backup_restic_forget_options }} {% if item.vars.restic_check_enabled | d(backup_restic_check_enabled) %} echo "Checking restic data..." - restic --quiet check + {{ backup_restic_command }} --quiet check {% endif %} {% endif %} }