Skip to content

Commit

Permalink
Add variables to customize path to commands
Browse files Browse the repository at this point in the history
  • Loading branch information
boutetnico committed Jun 28, 2023
1 parent ad8edd0 commit 4002ddc
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 50 deletions.
4 changes: 4 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | |
Expand Down
4 changes: 4 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions templates/docker_mariabackup.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,21 @@ 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 %}

{% 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 }} \
Expand All @@ -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 %}
}
Expand Down
14 changes: 7 additions & 7 deletions templates/files.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,21 @@ 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 %}

{% 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 }} \
Expand All @@ -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 %}
}
Expand Down
14 changes: 7 additions & 7 deletions templates/influxdb.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,21 @@ 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 %}

{% 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 }} \
Expand All @@ -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 %}
}
Expand Down
14 changes: 7 additions & 7 deletions templates/mongodump.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,21 @@ 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 %}

{% 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 }} \
Expand All @@ -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 %}
}
Expand Down
14 changes: 7 additions & 7 deletions templates/mysqldump.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,21 @@ 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 %}

{% 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 }} \
Expand All @@ -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 %}
}
Expand Down
16 changes: 8 additions & 8 deletions templates/s3_bucket.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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}/
Expand Down Expand Up @@ -71,21 +71,21 @@ 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 %}

{% 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 }} \
Expand All @@ -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 %}
}
Expand Down
14 changes: 7 additions & 7 deletions templates/xtrabackup.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,21 @@ 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 %}

{% 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 }} \
Expand All @@ -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 %}
}
Expand Down

0 comments on commit 4002ddc

Please sign in to comment.