test_export_data_command.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env bash
  2. # Test for the export-data admin command against sqlite and postgres
  3. # Expects Synapse to have been already installed with `poetry install --extras postgres`.
  4. # Expects `poetry` to be available on the `PATH`.
  5. set -xe
  6. cd "$(dirname "$0")/../.."
  7. echo "--- Generate the signing key"
  8. # Generate the server's signing key.
  9. poetry run synapse_homeserver --generate-keys -c .ci/sqlite-config.yaml
  10. echo "--- Prepare test database"
  11. # Make sure the SQLite3 database is using the latest schema and has no pending background update.
  12. poetry run update_synapse_database --database-config .ci/sqlite-config.yaml --run-background-updates
  13. # Run the export-data command on the sqlite test database
  14. poetry run python -m synapse.app.admin_cmd -c .ci/sqlite-config.yaml export-data @anon-20191002_181700-832:localhost:8800 \
  15. --output-directory /tmp/export_data
  16. # Test that the output directory exists and contains the rooms directory
  17. dir_r="/tmp/export_data/rooms"
  18. dir_u="/tmp/export_data/user_data"
  19. if [ -d "$dir_r" ] && [ -d "$dir_u" ]; then
  20. echo "Command successful, this test passes"
  21. else
  22. echo "No output directories found, the command fails against a sqlite database."
  23. exit 1
  24. fi
  25. # Create the PostgreSQL database.
  26. psql -c "CREATE DATABASE synapse"
  27. # Port the SQLite databse to postgres so we can check command works against postgres
  28. echo "+++ Port SQLite3 databse to postgres"
  29. poetry run synapse_port_db --sqlite-database .ci/test_db.db --postgres-config .ci/postgres-config.yaml
  30. # Run the export-data command on postgres database
  31. poetry run python -m synapse.app.admin_cmd -c .ci/postgres-config.yaml export-data @anon-20191002_181700-832:localhost:8800 \
  32. --output-directory /tmp/export_data2
  33. # Test that the output directory exists and contains the rooms directory
  34. dir_r2="/tmp/export_data2/rooms"
  35. dir_u2="/tmp/export_data2/user_data"
  36. if [ -d "$dir_r2" ] && [ -d "$dir_u2" ]; then
  37. echo "Command successful, this test passes"
  38. else
  39. echo "No output directories found, the command fails against a postgres database."
  40. exit 1
  41. fi