From 4c2e1a05881df3bfb1e0b8f3bd36139310e5f47b Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Tue, 1 Jan 2019 15:16:13 +0200 Subject: [PATCH] Make SQLite database import work with server files, not local This is a simplification and a way to make it consistent with how we do Postgres imports (see 6d89319822f4b2ecb), using files coming from the server, not from the local machine. --- docs/importing-sqlite.md | 14 +++-- roles/matrix-server/defaults/main.yml | 1 - .../tasks/import/import_sqlite_db.yml | 52 +++++++++---------- 3 files changed, 35 insertions(+), 32 deletions(-) diff --git a/docs/importing-sqlite.md b/docs/importing-sqlite.md index f7aa4c017..cd9917b42 100644 --- a/docs/importing-sqlite.md +++ b/docs/importing-sqlite.md @@ -8,8 +8,16 @@ using an SQLite database. If you have such a Matrix Synapse setup and wish to migrate it here (and over to PostgreSQL), this command is for you. -Run this command (make sure to replace `` with a file path on your local machine): - ansible-playbook -i inventory/hosts setup.yml --extra-vars='local_path_homeserver_db=' --tags=import-sqlite-db +## Prerequisites -**Note**: `` must be a file path to a `homeserver.db` file on your local machine (not on the server!). This file is copied to the server and imported. +Before doing the actual import, **you need to upload your SQLite database file to the server**. + + +## Importing + +Run this command (make sure to replace `` with a file path on your server): + + ansible-playbook -i inventory/hosts setup.yml --extra-vars='server_path_homeserver_db=' --tags=import-sqlite-db + +**Note**: `` must be a file path to a `homeserver.db` file on the server (not on your local machine!). \ No newline at end of file diff --git a/roles/matrix-server/defaults/main.yml b/roles/matrix-server/defaults/main.yml index c504eeebf..15e7dfce1 100644 --- a/roles/matrix-server/defaults/main.yml +++ b/roles/matrix-server/defaults/main.yml @@ -18,7 +18,6 @@ matrix_user_gid: 991 matrix_base_data_path: "/matrix" matrix_environment_variables_data_path: "{{ matrix_base_data_path }}/environment-variables" -matrix_scratchpad_dir: "{{ matrix_base_data_path }}/scratchpad" matrix_static_files_base_path: "{{ matrix_base_data_path }}/static-files" matrix_homeserver_url: "https://{{ hostname_matrix }}" diff --git a/roles/matrix-server/tasks/import/import_sqlite_db.yml b/roles/matrix-server/tasks/import/import_sqlite_db.yml index 102ef22a4..8b8c02860 100644 --- a/roles/matrix-server/tasks/import/import_sqlite_db.yml +++ b/roles/matrix-server/tasks/import/import_sqlite_db.yml @@ -1,31 +1,29 @@ --- +# Pre-checks + - name: Fail if playbook called incorrectly - fail: msg="The `local_path_homeserver_db` variable needs to be provided to this playbook, via --extra-vars" - when: "local_path_homeserver_db is not defined or local_path_homeserver_db.startswith('<')" + fail: msg="The `server_path_homeserver_db` variable needs to be provided to this playbook, via --extra-vars" + when: "server_path_homeserver_db is not defined or server_path_homeserver_db.startswith('<')" - name: Check if the provided SQLite homeserver.db file exists - stat: path="{{ local_path_homeserver_db }}" - delegate_to: 127.0.0.1 - become: false - register: local_path_homeserver_db_stat + stat: path="{{ server_path_homeserver_db }}" + register: result_server_path_homeserver_db_stat - name: Fail if provided SQLite homeserver.db file doesn't exist - fail: msg="File cannot be found on the local machine at {{ local_path_homeserver_db }}" - when: not local_path_homeserver_db_stat.stat.exists + fail: msg="File cannot be found on the local machine at {{ server_path_homeserver_db }}" + when: not result_server_path_homeserver_db_stat.stat.exists -- name: Ensure scratchpad directory exists - file: - path: "{{ matrix_scratchpad_dir }}" - state: directory - mode: 0755 - owner: "{{ matrix_user_username }}" - group: "{{ matrix_user_username }}" -- name: Ensure provided SQLite homeserver.db file is copied to scratchpad directory on the server - synchronize: - src: "{{ local_path_homeserver_db }}" - dest: "{{ matrix_scratchpad_dir }}/homeserver.db" +# Defaults + +- name: Set postgres_start_wait_time, if not provided + set_fact: + postgres_start_wait_time: 15 + when: "postgres_start_wait_time|default('') == ''" + + +# Actual import work - name: Ensure matrix-postgres is stopped service: name=matrix-postgres state=stopped daemon_reload=yes @@ -46,8 +44,11 @@ - name: Ensure matrix-postgres is started service: name=matrix-postgres state=restarted daemon_reload=yes -- name: Wait a while, so that Postgres can manage to start - pause: seconds=7 +- name: Wait a bit, so that Postgres can start + wait_for: + timeout: "{{ postgres_start_wait_time }}" + delegate_to: 127.0.0.1 + become: false # If the actual migration command (below) fails, it will leave a container behind. # Starting it again later will relaunch that one, which may or may not work. @@ -64,16 +65,11 @@ detach: no cleanup: yes entrypoint: /usr/local/bin/python - command: "/usr/local/bin/synapse_port_db --sqlite-database /scratchpad/homeserver.db --postgres-config /data/homeserver.yaml" + command: "/usr/local/bin/synapse_port_db --sqlite-database {{ server_path_homeserver_db }} --postgres-config /data/homeserver.yaml" user: "{{ matrix_user_uid }}:{{ matrix_user_gid }}" volumes: - "{{ matrix_synapse_config_dir_path }}:/data" - "{{ matrix_synapse_run_path }}:/matrix-run" - - "{{ matrix_scratchpad_dir }}:/scratchpad" + - "{{ server_path_homeserver_db }}:/{{ server_path_homeserver_db }}:ro" networks: - name: "{{ matrix_docker_network }}" - -- name: Ensure scratchpad directory is deleted - file: - path: "{{ matrix_scratchpad_dir }}" - state: absent