Эх сурвалжийг харах

added source_host option to backup ssh hosts

Fabian Peter Hammerle 8 жил өмнө
parent
commit
546fd90b6a
1 өөрчлөгдсөн 15 нэмэгдсэн , 1 устгасан
  1. 15 1
      tasks/main.yml

+ 15 - 1
tasks/main.yml

@@ -6,13 +6,27 @@
 - name: generate commands
   set_fact:
     backup_command: |-
+      {% if item.source_host is defined %}
+      mount_path="$(mktemp --tmpdir --directory ansible-duplicity-sshfs-XXXXXXXX)"; sshfs "{{item.source_host}}:{{item.source_path}}" $mount_path;
+      {%- endif %}
       duplicity --no-encryption --no-print-statistics --verbosity warning
       {%- for selector in item.selectors|default([]) %}
       {% if selector['option'] in ['exclude', 'include'] %}
        --{{selector['option']}} "{{selector['shell_pattern']}}"
       {%- endif %}
       {% endfor %}
-       "{{item.source_path}}" "{{item.target_url}}"
+      {%- if item.source_host is defined %}
+       --name "{{item.source_host}}:{{item.source_path}}"
+      {%- endif %}
+      {%- if item.source_host is defined %}
+       --allow-source-mismatch "$mount_path"
+      {%- else %}
+       "{{item.source_path}}"
+      {%- endif %}
+       "{{item.target_url}}";
+      {%- if item.source_host is defined %}
+      fusermount -u "$mount_path" && rm -r "$mount_path";
+      {%- endif %}
   with_items: '{{duplicity_backups}}'
   register: duplicity_backup_commands
 - name: setup cron jobs