diff --git a/ansible/idr-omero-restoredb-pg.yml b/ansible/idr-omero-restoredb-pg.yml new file mode 100644 index 00000000..0c5d0f51 --- /dev/null +++ b/ansible/idr-omero-restoredb-pg.yml @@ -0,0 +1,44 @@ +--- +# restore omero database from compressed dump + +- name: postgres | download from rsync + become: yes + synchronize: + mode: pull + compress: no + src: "{{ rsync_host }}sql/latest/" + dest: "{{ rsync_dest_dbdump }}" + delegate_to: "{{ hostvars[groups[idr_environment | default('idr') + '-database-hosts'][0]]['ansible_' + (idr_net_iface | default('eth0'))]['ipv4']['address']}}" + +- name: postgres | restore with compression | drop schema + become: yes + become_user: postgres + command: psql -d {{ omero_dbname }} -c "DROP SCHEMA public CASCADE;" + +- name: postgres | restore with compression | create schema + become: yes + become_user: postgres + command: psql -d {{ omero_dbname }} -c "CREATE SCHEMA public;" + +- name: postgres | restore with compression | grant permissions1 + become: yes + become_user: postgres + command: psql -d {{ omero_dbname }} -c "GRANT ALL ON SCHEMA public TO postgres;" + +- name: postgres | restore with compression | grant permissions2 + become: yes + become_user: postgres + command: psql -d {{ omero_dbname }} -c "GRANT ALL ON SCHEMA public TO public;" + +# TODO: fix when https://github.com/ansible/ansible/pull/20627 +- name: postgres | restore with compression + become: yes + become_user: postgres + command: pg_restore -Fd -j8 -d {{ omero_dbname }} --exit-on-error /tmp/db_dump + +- name: postgres | restore password table + become: yes + become_user: postgres + command: psql -d {{ omero_dbname }} -c "INSERT INTO password(experimenter_id,hash) VALUES ({{ item.uid }},'{{ item.password }}');" + with_items: "{{ omero_dbreset_user_passwords | default([]) }}" + diff --git a/ansible/idr-omero-restoredb-repo.yml b/ansible/idr-omero-restoredb-repo.yml new file mode 100644 index 00000000..e684790e --- /dev/null +++ b/ansible/idr-omero-restoredb-repo.yml @@ -0,0 +1,24 @@ +--- +# restore omero data repo + +- name: omero | restore FullText + become: yes + synchronize: + mode: pull + compress: no + delete: yes + recursive: yes + src: "{{ rsync_host }}omero/FullText" + dest: "{{ omero_datadir }}/" + delegate_to: "{{ hostvars[groups[idr_environment | default('idr') + '-omero-hosts'][0]]['ansible_' + (idr_net_iface | default('eth0'))]['ipv4']['address']}}" + +- name: omero | restore Thumbnails + become: yes + synchronize: + mode: pull + compress: no + delete: yes + recursive: yes + src: "{{ rsync_host }}omero/Thumbnails" + dest: "{{ omero_datadir }}/" + delegate_to: "{{ hostvars[groups[idr_environment | default('idr') + '-omero-hosts'][0]]['ansible_' + (idr_net_iface | default('eth0'))]['ipv4']['address']}}" diff --git a/ansible/idr-omero-restoredb.yml b/ansible/idr-omero-restoredb.yml new file mode 100644 index 00000000..44f84e63 --- /dev/null +++ b/ansible/idr-omero-restoredb.yml @@ -0,0 +1,78 @@ +# Example playbook for reseting Database and Data Repository +# +# This is initially aimed at maintenance tasks, e.g. restoring production database + + +# STOP +- hosts: > + {{ idr_environment | default('idr') }}-omero-hosts + + tasks: + - name: omero | stop omero server + become: yes + systemd: + name: omero + state: stopped + + +# DB MAINTENANCE +- hosts: > + {{ idr_environment | default('idr') }}-database-hosts + + tasks: + - name: postgres | rsync and reset db + become: yes + include: idr-omero-restoredb-pg.yml + when: omero_dbreset + + vars: + rsync_host: "rsync://idr-rsync.openmicroscopy.org/" + rsync_dest_dbdump: "/tmp/db_dump" + omero_dbname: idr + omero_dbreset: True + omero_dbreset_user_passwords: + - {'uid': 0, 'password': ""} + - {'uid': 1, 'password': ""} + - {'uid': 2, 'password': ""} + - {'uid': 52, 'password': ""} + + +# SERVER MAINTENANCE +- hosts: > + {{ idr_environment | default('idr') }}-omero-hosts + + pre_tasks: + - name: omero | restore data repository + become: yes + include: idr-omero-restoredb-repo.yml + when: omero_datareporeset + + - name: Get database host + set_fact: + omero_db_host_ansible: "{{ hostvars[groups[idr_environment | default('idr') + '-database-hosts'][0]]['ansible_' + (idr_net_iface | default('eth0'))]['ipv4']['address']}}" + + # Upgrade and start + # roles: + # - role: openmicroscopy.omero-server + # omero_dbhost: "{{ omero_db_host_ansible }}" + # omero_dbname: idr + # omero_upgrade: True + # omero_systemd_setup: True + # omero_db_create: False + # omero_system_managedrepo_group: idr-data + + vars: + rsync_host: "rsync://idr-rsync.openmicroscopy.org/" + omero_datareporeset: False + + +# START +- hosts: > + {{ idr_environment | default('idr') }}-omero-hosts + + tasks: + - name: omero | start omero.server + become: yes + systemd: + name: omero + state: started