Skip to content

Commit

Permalink
Implementing fallback option for backrest
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjavala committed Feb 14, 2017
1 parent 6283d0e commit 9df60f6
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion incr-postgresdbbackup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
sudo: yes
roles:
- { role: httpd-maintenance, maintenance_status: start}
- { role: pgbackrest-backup, when: backup_type == 'all' or options == 'postgres' or options == 'all'}
- { role: pgbackrest-backup, when: backup_type == 'all' or options == 'postgres' or options == 'all' or options == 'openelis' or options == 'openerp' }
- { role: httpd-maintenance, maintenance_status: end}

2 changes: 1 addition & 1 deletion incr-postgresdbrestore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
sudo: yes
roles:
- { role: httpd-maintenance, maintenance_status: start}
- { role: pgbackrest-restore, when: restore_type == 'all' or options == 'postgres' or options == 'all'}
- { role: pgbackrest-restore, when: restore_type == 'all' or options == 'postgres' or options == 'all' or strategy == 'dump'}
- { role: httpd-maintenance, maintenance_status: end}


2 changes: 2 additions & 0 deletions roles/pgbackrest-backup/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ postgres:
path: /var/lib/pgbackrest
retention_limit: 2
copy_to_local_machine: no


5 changes: 4 additions & 1 deletion roles/pgbackrest-backup/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
register: installed_pgbackrest
ignore_errors: True

- debug:
msg: ">>>{{installed_pgbackrest}}<<<<"

- name: Fallback to pgsqldump if pgbackrest not installed
include: pgsqldumpbackup.yml
when: installed_pgbackrest.stdout.find("command not found") == 0
when: installed_pgbackrest.stdout.find("pgbackrest [options] [command]") == -1


- name: Editing pgbackrest.conf file
Expand Down
8 changes: 4 additions & 4 deletions roles/pgbackrest-backup/tasks/pgsqldumpbackup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
command: date +%Y%m%d-%H%M%S
register: time

- name: Take {{db_name}} DB backup
shell: pg_dump -Upostgres --create {{ db_name }} | gzip > /db-backup/{{ db_name }}_dump_{{ time.stdout }}.sql.gz
- name: Take {{ options }} DB backup
shell: pg_dump -Upostgres --create {{ options }} | gzip > /db-backup/{{ options }}_dump_{{ time.stdout }}.sql.gz
sudo: yes

- name: Create /db-backup directory in local machine
local_action: file path=/db-backup state=directory mode=0777
when: copy_to_local_machine == "yes"

- name: Copy {{db_name}} backup file to local machine
fetch: src=/db-backup/{{ db_name }}_dump_{{time.stdout}}.sql.gz dest=/db-backup/ flat=yes
- name: Copy {{options}} backup file to local machine
fetch: src=/db-backup/{{ options }}_dump_{{time.stdout}}.sql.gz dest=/db-backup/ flat=yes
when: copy_to_local_machine == "yes"
1 change: 1 addition & 0 deletions roles/pgbackrest-restore/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
strategy: full
file_path: /db-backup
logfile: /var/log/dbrestore.log
postgres:
path: /var/lib/pgbackrest
Expand Down
8 changes: 7 additions & 1 deletion roles/pgbackrest-restore/tasks/pgsqldumprestore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@
path=/db-restore
state=directory

- name: Copy {[ db_name }} backup to the machine
- name: Copy {{ db_name }} backup to the machine
copy: src={{ file_path }}
dest=/db-restore/{{ db_name }}_dump.sql.gz
mode=644
owner={{ bahmni_user }}
group={{ bahmni_group }}

- name: Start PostgreSQL
service:
name=postgresql-{{ postgres_version }}
state=running
ignore_errors: true

- name: Drop {{ db_name }} database
postgresql_db:
name={{ db_name }}
Expand Down

0 comments on commit 9df60f6

Please sign in to comment.