diff --git a/Dockerfile b/Dockerfile index 7b55e08..b95e312 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM alpine:3.10 +FROM alpine:3.12 MAINTAINER tess@ten7.com # Update the package list and install Ansible. diff --git a/ansible/build.yml b/ansible/build.yml index a3329e6..e2012fc 100644 --- a/ansible/build.yml +++ b/ansible/build.yml @@ -27,6 +27,7 @@ - "py3-mysqlclient" - "py3-pip" - "rsync" + - "rclone" - "tree" notify: - clear apk cache diff --git a/ansible/group_vars/backup.yml b/ansible/group_vars/backup.yml index f5ecaee..88f1644 100644 --- a/ansible/group_vars/backup.yml +++ b/ansible/group_vars/backup.yml @@ -1,5 +1,5 @@ --- -flighdeck_motd_name: "Tractorbeam 2.4.0" +flighdeck_motd_name: "Tractorbeam 2.5.0" flightdeck_groups: - name: "backup" diff --git a/ansible/roles/tractorbeam/tasks/main.yml b/ansible/roles/tractorbeam/tasks/main.yml index f6d7120..88895ce 100644 --- a/ansible/roles/tractorbeam/tasks/main.yml +++ b/ansible/roles/tractorbeam/tasks/main.yml @@ -107,6 +107,8 @@ s3/awscli.yml\ {% elif _backup.method | default('s3cmd') == 'gsutil' %}\ s3/gsutil.yml\ + {% elif _backup.method | default('s3cmd') == 'rclone' %}\ + s3/rclone.yml\ {% else %}\ s3/s3cmd.yml\ {% endif %}" diff --git a/ansible/roles/tractorbeam/tasks/s3/rclone.yml b/ansible/roles/tractorbeam/tasks/s3/rclone.yml new file mode 100644 index 0000000..ac61a79 --- /dev/null +++ b/ansible/roles/tractorbeam/tasks/s3/rclone.yml @@ -0,0 +1,86 @@ +--- +- name: Create a tempfile for the rclone config + tempfile: + prefix: "tractorbeam-rclone-" + suffix: ".conf" + state: file + register: _rclone_conf +- name: Template the rclone conf + copy: + content: | + [source] + type = s3 + provider = {{ _backup.srcProvider | default('AWS') }} + env_auth = false + access_key_id = {{ _src_access_key }} + secret_access_key = {{ _src_secret_key }} + endpoint = {{ _backup.srcEndpoint | default('') | regex_replace('[A-z]*://', '') }} + region = {{ _backup.srcRegion | default('') }} + acl = {{ _backup.srcAcl | default('private') }} + + [dest] + type = s3 + provider = {{ _backup.provider | default('AWS') }} + env_auth = false + access_key_id = {{ _dest_access_key }} + secret_access_key = {{ _dest_secret_key }} + endpoint = {{ _backup.endpoint | default('') | regex_replace('[A-z]*://', '') }} + region = {{ _backup.region | default('') }} + acl = {{ _backup.acl | default('private') }} + dest: "{{ _rclone_conf.path }}" + vars: + _src_access_key: "\ + {% if _backup.srcAccessKeyFile is defined %}\ + {{ lookup('file', _backup.srcAccessKeyFile) }}\ + {% else %}\ + {{ _backup.srcAccessKey | default(omit) }}\ + {% endif %}" + _src_secret_key: "\ + {% if _backup.srcSecretKeyFile is defined %}\ + {{ lookup('file', _backup.srcSecretKeyFile) }}\ + {% else %}\ + {{ _backup.srcSecretKey | default(omit) }}\ + {% endif %}" + _dest_access_key: "\ + {% if _backup.accessKeyFile is defined %}\ + {{ lookup('file', _backup.accessKeyFile) }}\ + {% else %}\ + {{ _backup.accessKey | default(omit) }}\ + {% endif %}" + _dest_secret_key: "\ + {% if _backup.secretKeyFile is defined %}\ + {{ lookup('file', _backup.secretKeyFile) }}\ + {% else %}\ + {{ _backup.secretKey | default(omit) }}\ + {% endif %}" +- name: Create a cache directory for the backup + file: + state: directory + path: "{{ _backup.cacheDir }}" + owner: "backup" + group: "backup" + mode: "u=rwx,g=rxw,o=rwx" + when: + - _backup.cacheDir is defined +- name: Sync files using rclone + shell: > + rclone sync + source:/{{ _backup.srcBucket }}/{% if _backup.prefix is defined %}{{ _backup.prefix }}/{% endif %} + dest:/{{ _backup.bucket }}/{% if _backup.prefix is defined %}{{ _backup.prefix }}/{% endif %} + --config="{{ _rclone_conf.path }}" + {% for _exclude in _backup.excludes | default(_tractorbeam_default_files_excludes) %} + --exclude="{{ _exclude }}"{{ '' }} + {% endfor %} + {% if _backup.delete | default(true) %} + --delete-during + {% endif %} + {% if (flightdeck_debug | default(false)) != true %} + --quiet + {% else %} + --verbose="4" + {% endif %} + register: _froms3_result + until: _froms3_result.rc == 0 + retries: "{{ _backup.retryCount | default(3) }}" + delay: "{{ _backup.retryDelay | default(30) }}" +- include_tasks: "healhcheck.yml"