Skip to content

Cloning eScriptorium

Stefan Weil edited this page Oct 30, 2024 · 6 revisions

Cloning an instance of eScriptorium

Here an existing instance is cloned to get a new test instance which can be updated with the latest code. The test instance starts with the same users and projects as the original instance.

We want to create the cloned instance on the same server as the original instance. Both instances run natively on Debian stable (no Docker installation).

The following commands must be run by root.

First make sure that there is enough disk space available for a new database. Then create a new PostgreSQL database es_next from the backup of the original database escriptorium.

# Check the sizes of all PostgreSQL databases. The largest one might be from eScriptorium.
du -BG -sc /var/lib/postgresql/15/main/base/*

# Now check the available disk space for the new database.
# It must be large enough for the cloned database.
df -BG /var/lib/postgresql/15/main/base

# Create a new PostgreSQL database `es_next` from the backup of the original database `escriptorium`.
# This takes much time (more than an hour for a database with about 52 GiB).
zcat /var/lib/autopostgresqlbackup/daily/escriptorium/escriptorium_2024-10-30_07h36m.Wednesday.sql.gz | sed -e 's/CREATE DATABASE \([^ ]*\)/CREATE DATABASE es_next/g'     -e 's/ALTER DATABASE \([^ ]*\)/ALTER DATABASE es_next/g'     -e 's/\\connect \([^ ]*\)/\\connect es_next/g' | psql -d postgres

Now duplicate code and data from /opt/escriptorium to /opt/es_next.

# Check the size of the existing directory.
du -BG -sc /opt/escriptorium

# Now check the available disk space for the new directory.
# It must be large enough for a copy of the existing one.
df -BG /opt/escriptorium

# Create the copy. This also takes much time.
cp -a /opt/escriptorium /opt/es_next

Now clean the directory /opt/es_next and update the code. Then create a new virtual Python environment:

python3.11 -m venv /opt/es_next/venv3.11
source /opt/es_next/venv3.11/bin/activate
pip install -U pip setuptools wheel
pip install -r app/requirements.txt

# Install node modules.
cd /opt/es_next/front
npm ci
npm run build

# Migrate the new database.
cd /opt/es_next/app
python manage.py migrate --settings escriptorium.local_settings