41 lines
1.0 KiB
YAML
41 lines
1.0 KiB
YAML
---
|
|
- name: Backup Docker volumes from remote server
|
|
hosts: all
|
|
become: yes
|
|
vars:
|
|
backup_dir: "./backups"
|
|
backup_name: "volumes_{{ ansible_date_time.iso8601_basic_short }}"
|
|
archive_path: "/tmp/docker_volumes_backup_{{ ansible_date_time.iso8601_basic_short }}.tar.gz"
|
|
|
|
|
|
tasks:
|
|
- name: Create archive of docker volumes
|
|
become: yes
|
|
archive:
|
|
path: /opt/docker/.
|
|
dest: /tmp/{{ backup_name }}.tar.gz
|
|
format: gz
|
|
|
|
- name: Fetch archive to local machine
|
|
become: yes
|
|
fetch:
|
|
src: /tmp/{{ backup_name }}.tar.gz
|
|
dest: ./backups/archive/
|
|
flat: yes
|
|
|
|
- name: Clean up archive on remote
|
|
become: yes
|
|
file:
|
|
path: /tmp/{{ backup_name }}.tar.gz
|
|
state: absent
|
|
|
|
- name: Extract archive locally
|
|
become: no
|
|
delegate_to: localhost
|
|
run_once: true
|
|
ansible.builtin.unarchive:
|
|
src: ./backups/archive/{{ backup_name }}.tar.gz
|
|
dest: ./backups/
|
|
remote_src: no
|
|
# extra_opts: [ "--strip-components=3" ]
|