Repository navigation
docs: correct MSColab database backup and restore commands #3409
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -217,11 +217,37 @@ directly to the server, e.g. :code:`http://127.0.0.1:8087`, and refuse the endpo | |
| Backup Data Base | ||
| ................ | ||
|
|
||
| For backups you can dump by `pg_dump -d mscolab -f output.sql` the sqlite database | ||
| and restore it by `psql -v ON_ERROR_STOP=1 < new_db.sql` | ||
| Use the backup tools for the database configured by ``SQLALCHEMY_DATABASE_URI``. | ||
|
|
||
| On a PostgreSQL db you can regularly do backups by creating a dump | ||
| by `pg_dump <https://www.postgresql.org/docs/current/app-pgdump.html>`_ using a cron job :: | ||
| For SQLite, use the `sqlite3 command-line shell <https://www.sqlite.org/cli.html>`_. | ||
| With the default database path, create a backup in your home directory with:: | ||
|
|
||
| sqlite3 -readonly "$HOME/mss/colabdata/mscolab.db" ".backup '$HOME/mscolab-backup.db'" | ||
|
|
||
| To restore the backup, stop MSColab and any other process using its database, then run the following commands. | ||
| Only restore from an existing, non-empty backup file. This replaces the current database contents:: | ||
|
|
||
| if [ -s "$HOME/mscolab-backup.db" ]; then | ||
| sqlite3 "$HOME/mss/colabdata/mscolab.db" ".restore '$HOME/mscolab-backup.db'" | ||
| else | ||
| echo "Backup file missing or empty; database was not restored." >&2 | ||
| fi | ||
|
|
||
| Adjust the database and backup file paths in both examples if you use custom locations. | ||
|
|
||
| For PostgreSQL, create a SQL dump with `pg_dump <https://www.postgresql.org/docs/current/app-pgdump.html>`_:: | ||
|
|
||
| pg_dump -d mscolab -f output.sql | ||
|
|
||
| Create an empty PostgreSQL database (named ``mscolab_restored`` in this example), then restore the same dump | ||
| with `psql <https://www.postgresql.org/docs/current/app-psql.html>`_:: | ||
|
|
||
| psql -d mscolab_restored -v ON_ERROR_STOP=1 -f output.sql | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| To use the restored database for recovery, stop MSColab, update ``SQLALCHEMY_DATABASE_URI`` in | ||
| ``mscolab_settings.py`` to point to ``mscolab_restored``, and restart the server. | ||
|
Comment on lines
+247
to
+248
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update scheduled dumps after switching databases. If an operator uses the documented cron job, it continues to dump
|
||
| Use the database names and connection options for your PostgreSQL installation. | ||
| Regular PostgreSQL dumps can also be scheduled using a cron job:: | ||
|
|
||
| #!/bin/bash | ||
| timestamp=$(date +%Y%m%d_%H%M) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restrict the SQLite backup file's permissions.
The
.backupcommand creates a new backup file. SQLite creates new Unix database files with mode 0644 before the umask applies. With a common umask of 022, the backup is readable by any local user who can traverse$HOME. The backup contains the same chat messages and account data as the live database.The live database uses the same default mode. Its exposure depends on the permissions of its
colabdatadirectory. This makes the backup a hardening gap. It becomes a material exposure when the data directory is restricted but$HOMEis not.Create the backup with a restrictive umask:
Suggested fix
Writing to an existing backup file keeps its current mode. Remove the old backup file or run
chmod 600on it before you create a new backup.Committable suggestion