Files
nextcloud-utils/copy_all_users.yml

20 lines
919 B
YAML

---
- name: Copy user database from a one nextcloud to another
hosts: all
vars:
container_name: "db"
tasks:
- name: Backup Postgres necessary table on src
block:
- shell: "docker exec -u postgres {{ container_name }} pg_dump --clean -t public.oc_accounts -t public.oc_users -t public.oc_groups -t public.oc_group_admin -t public.oc_group_user nextcloud > /tmp/nextcloud_backup.sql"
- name: Fetch the SQL dump from src
run_once: yes
fetch: src=/tmp/nextcloud_backup.sql dest=/tmp/ flat=yes
when: inventory_hostname == "nextcloud-src"
- name: Restore Postgres necessary table on dst
block:
- name: Copy the SQL dump to dst
copy: src=/tmp/nextcloud_backup.sql dest=//tmp/
become: yes
- shell: "docker exec -i -u postgres {{ container_name }} psql nextcloud < /tmp/nextcloud_backup.sql"
when: inventory_hostname == "nextcloud-dst"