Skip to content

Commit

Permalink
backup and restore maas snap
Browse files Browse the repository at this point in the history
  • Loading branch information
SK1Y101 committed Aug 20, 2023
1 parent e8fa52a commit 375267e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions group_vars/all/20-database
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ maas_postgres_version_number: "{{ 14 if ansible_distribution_major_version | flo
maas_postgres_replication_user: "replicator"
maas_postgres_backup_dir: "/tmp/maas_backup/"
maas_postgres_backup_path: "{{ maas_postgres_backup_dir }}dump.sql.gz"
maas_snap_backup_path: "{{ '' if maas_install_deb | bool else '/var/lib/maas/snap_backup' }}"
maas_config_backup_path: "{{ '/etc/maas/' if maas_install_deb | bool else '' }}"
maas_runtime_backup_path: "{{ '/var/lib/maas/' if maas_install_deb | bool else '' }}"
maas_exclude_backup_path: "{{ '/var/lib/maas/boot-resources/' if maas_install_deb | bool else '' }}"
Expand Down
9 changes: 9 additions & 0 deletions restore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
become: true
gather_facts: true

- hosts: maas_region_controller
tasks:
- name: Reset database triggers
ansible.builtin.command: maas-region dbupgrade
when: ('maas_region_controller' in group_names) and (not maas_install_deb | bool)
run_once: true
become: true
gather_facts: true

- hosts:
- maas_postgres
- maas_region_controller
Expand Down
22 changes: 22 additions & 0 deletions roles/common/tasks/backup.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
---
- name: Stop MAAS snap
ansible.builtin.command: snap stop maas
when: (('maas_region_controller' in group_names) or ('maas_rack_controller' in group_names)) and (not maas_install_deb | bool)

- name: Backup MAAS snap
ansible.builtin.command: snap save maas
register: snap_id
when: (('maas_region_controller' in group_names) or ('maas_rack_controller' in group_names)) and (not maas_install_deb | bool)

- name: Verify snap backup valid
ansible.builtin.command: "snap check-snapshot {{ snap_id }}"
when: (('maas_region_controller' in group_names) or ('maas_rack_controller' in group_names)) and (not maas_install_deb | bool)

- name: Export snap backup
ansible.builtin.command: "snap export-snapshot {{ snap_id }} {{ maas_snap_backup_path }}"
when: (('maas_region_controller' in group_names) or ('maas_rack_controller' in group_names)) and (not maas_install_deb | bool)

- name: Generate List of Archiveable Directories
ansible.builtin.set_fact:
archive_list: "{{ archive_list | default([]) + [item] }}"
loop:
- "{{ maas_postgres_backup_dir if 'maas_postgres' in group_names else None }}"
- "{{ maas_snap_backup_path if (('maas_region_controller' in group_names) or ('maas_rack_controller' in group_names)) else None }}"
- "{{ maas_config_backup_path if (('maas_region_controller' in group_names) or ('maas_rack_controller' in group_names)) else None }}"
- "{{ maas_runtime_backup_path if (('maas_region_controller' in group_names) or ('maas_rack_controller' in group_names)) else None }}"
when: item
Expand All @@ -30,3 +48,7 @@
path: "{{ maas_backup_dest_path }}"
state: absent
when: archive_list is defined

- name: Start MAAS snap
ansible.builtin.command: snap start maas
when: (('maas_region_controller' in group_names) or ('maas_rack_controller' in group_names)) and (not maas_install_deb | bool)

Check failure on line 54 in roles/common/tasks/backup.yaml

View workflow job for this annotation

GitHub Actions / build

yaml[new-line-at-end-of-file]

No new line character at the end of file
9 changes: 9 additions & 0 deletions roles/common/tasks/restore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
ansible.builtin.command: snap stop maas
when: (('maas_region_controller' in group_names) or ('maas_rack_controller' in group_names)) and (not maas_install_deb | bool)

- name: Import snap data
ansible.builtin.command: "snap import-snapshot /tmp/maas_backup/{{ maas_snap_backup_path }}"
register: snap_id
when: (('maas_region_controller' in group_names) or ('maas_rack_controller' in group_names)) and (not maas_install_deb | bool)

- name: Restore Snap data
ansible.builtin.command: "snap restore {{ snap_id }}"
when: (('maas_region_controller' in group_names) or ('maas_rack_controller' in group_names)) and (not maas_install_deb | bool)

- name: Restore Config
ansible.builtin.command: "mv /tmp/maas_backup/etc/maas {{ maas_restore_config_path }}"
when: ('maas_region_controller' in group_names) or ('maas_rack_controller' in group_names)
Expand Down
2 changes: 1 addition & 1 deletion roles/maas_postgres/tasks/restore.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: Restore database using the tar format
- name: Restore database from file
community.postgresql.postgresql_db:
name: "{{ maas_postgres_database }}"
state: restore
Expand Down

0 comments on commit 375267e

Please sign in to comment.