Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore #9

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions ansible/idr-omero-restoredb-pg.yml
Original file line number Diff line number Diff line change
@@ -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([]) }}"

24 changes: 24 additions & 0 deletions ansible/idr-omero-restoredb-repo.yml
Original file line number Diff line number Diff line change
@@ -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']}}"
78 changes: 78 additions & 0 deletions ansible/idr-omero-restoredb.yml
Original file line number Diff line number Diff line change
@@ -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