Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
Add rclone method.
Browse files Browse the repository at this point in the history
  • Loading branch information
socketwench committed Jul 20, 2020
1 parent 08530ba commit 51e2d9e
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alpine:3.10
FROM alpine:3.12
MAINTAINER tess@ten7.com

# Update the package list and install Ansible.
Expand Down
1 change: 1 addition & 0 deletions ansible/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- "py3-mysqlclient"
- "py3-pip"
- "rsync"
- "rclone"
- "tree"
notify:
- clear apk cache
Expand Down
2 changes: 1 addition & 1 deletion ansible/group_vars/backup.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
flighdeck_motd_name: "Tractorbeam 2.4.0"
flighdeck_motd_name: "Tractorbeam 2.5.0"

flightdeck_groups:
- name: "backup"
Expand Down
2 changes: 2 additions & 0 deletions ansible/roles/tractorbeam/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}"
Expand Down
86 changes: 86 additions & 0 deletions ansible/roles/tractorbeam/tasks/s3/rclone.yml
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 51e2d9e

Please sign in to comment.