summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--backup-playbook.yml60
-rw-r--r--group_vars/all.yml4
3 files changed, 63 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 2f371b2..682855b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@ vnc-passwd-dev
vnc-passwd-gen
vnc-password
vnc-password-gen
+backups
diff --git a/backup-playbook.yml b/backup-playbook.yml
new file mode 100644
index 0000000..5ac234d
--- /dev/null
+++ b/backup-playbook.yml
@@ -0,0 +1,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"
diff --git a/group_vars/all.yml b/group_vars/all.yml
index 411d60e..97eb83e 100644
--- a/group_vars/all.yml
+++ b/group_vars/all.yml
@@ -44,5 +44,5 @@ protect_stream_with_password: false
restreaming_platforms: []
-backup_dir_on_server: "~/backups"
-local_backup_dir: "backups"
+backup_dir_on_server: "~{{emacsconf_user}}/backups/"
+local_backup_dir: "backups/"