blob: 5ac234d110b8b536b1ef91a1d5016c135a49130a (
plain) (
blame)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# backup_playbook.yml
---
- name: Load vars
hosts: all
tags: always
tasks:
- include_vars:
file: prod-vars.yml
- name: Backup Etherpad
hosts: pad
remote_user: "{{ emacsconf_user }}"
become: false
vars_files:
- roles/pad/vars/main.yml
tasks:
- name: "Ensure the backup directory exists on the remote server"
ansible.builtin.file:
path: "{{ backup_dir_on_server }}"
state: directory
mode: '0755'
owner: "{{ emacsconf_user }}"
group: "{{ emacsconf_group }}"
- name: "Backup MySQL database"
community.mysql.mysql_db:
name: "{{ etherpad_mysql_database_name }}"
state: dump
target: "{{ backup_dir_on_server }}{{ etherpad_mysql_database_name }}.sql"
login_user: "{{ etherpad_mysql_database_user }}"
login_password: "{{ etherpad_mysql_database_password }}"
register: db_backup_result
- name: "Change ownership of the backup file"
ansible.builtin.file:
path: "{{ backup_dir_on_server }}{{ etherpad_mysql_database_name }}.sql"
owner: "{{ emacsconf_user }}"
group: "{{ emacsconf_group }}"
mode: '0644'
become: true
- name: "Log the backup status"
ansible.builtin.debug:
msg: "Database backup completed successfully. File is at {{ backup_dir_on_server }}{{ etherpad_mysql_database_name }}.sql"
- name: "Retrieve backup from prod and save locally"
hosts: localhost # This part runs on your local machine
connection: local
tasks:
- name: "Ensure the local backup directory exists"
ansible.builtin.file:
path: "{{ local_backup_dir }}"
state: directory
mode: '0755'
- name: "Fetch the database backup file"
ansible.posix.synchronize:
src: "{{ hostvars['pad'].ansible_ssh_user }}@{{ hostvars['pad'].ansible_host }}:{{ backup_dir_on_server }}{{ etherpad_mysql_database_name }}.sql"
dest: "{{ local_backup_dir }}"
mode: pull
archive: yes
compress: yes
rsync_path: "rsync"
|