-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdatabase_backup_playbook_awx.yaml
43 lines (36 loc) · 1.36 KB
/
database_backup_playbook_awx.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
---
- hosts: all
gather_facts: true
tasks:
- name: Create variables
set_fact:
db_file_name: "{{ db_backup_folder_path }}/{{ db_name }}_{{ ansible_date_time.date | replace('-','') }}.sql"
local_db_file_name: "{{ local_db_backup_folder_path }}/{{ db_name }}_{{ ansible_date_time.date | replace('-','') }}.sql"
- name: Confirm hostname
debug:
msg: Logged into the server.
- name: Debug
shell: |
whoami && df -h && ls -la /runner && ls -la /mnt
delegate_to: localhost
- name: Removing old backups
shell: |
cd {{ db_backup_folder_path }} && rm {{ db_file_name_pattern_to_delete }}
ignore_errors: yes
- name: Download Database to server
shell: |
mysqldump -u {{ db_user_name }} -p"{{ db_user_password }}" {{ db_name }} --quick --lock-tables=false > "{{ db_file_name }}" --no-tablespaces
no_log: false
- name: Wait until the database backup completed on server
wait_for:
path: "{{ db_file_name }}"
state: present
msg: "Timeout to find file {{ db_file_name }}"
- name: Downloading backup to local computer
ansible.builtin.fetch:
src: "{{ db_file_name }}"
dest: "{{ local_db_file_name }}"
flat: yes
- name: Download completed
debug:
msg: Database have been downloaded successfully.