playbooks/mongo backup.yml

21 lines
701 B
YAML
Raw Normal View History

2025-02-05 20:45:47 +03:30
- name: Backup MongoDB Databases
hosts: all
become: yes
tasks:
- name: Backup MongoDB databases
command: >
docker exec {{ mongodb_container }} mongodump
--db {{ item }}
--username {{ mongodb_user }}
--password {{ mongodb_password }}
--authenticationDatabase admin
2025-02-05 21:07:36 +03:30
--out {{ mongo_backup_dir }}
2025-02-05 20:45:47 +03:30
with_items: "{{ db_names }}"
2025-02-05 21:07:36 +03:30
- name: Get the current weekday
shell: date +%a
register: weekday
changed_when: false
- name: Archive each directory separately
command: >
tar -czf "{{ backup_dir }}/{{ item }}-{{ weekday.stdout }}.tar.gz" -C "{{ backup_dir }}" "{{ item }}"
loop: "{{ db_names }}"