diff options
author | Sacha Chua <sacha@sachachua.com> | 2025-09-22 14:56:15 -0400 |
---|---|---|
committer | Sacha Chua <sacha@sachachua.com> | 2025-09-22 14:56:33 -0400 |
commit | 576cb9e0be0992fb5d937a7d9bd95b657c3926eb (patch) | |
tree | 37a9ba9bc9667d85e6bdc38b6545228521cebdc9 | |
parent | ad89f305693baff9a2eb6a84ae70849809867e02 (diff) | |
download | emacsconf-ansible-576cb9e0be0992fb5d937a7d9bd95b657c3926eb.tar.xz emacsconf-ansible-576cb9e0be0992fb5d937a7d9bd95b657c3926eb.zip |
Starting point for backup playbook
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | backup-playbook.yml | 60 | ||||
-rw-r--r-- | group_vars/all.yml | 4 |
3 files changed, 63 insertions, 2 deletions
@@ -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/" |