Mirroring a Lino site

To mirror a Lino site means that you copy "everything" from one Lino site to another site. The other site might be either on the same server or on another server. If the other site runs a newer version of the application, mirroring also includes data migration. "Everything" means database content, uploaded files, local configuration files (but the details may vary).

Mirroring is referred to in two other documents, Installing a preview site and Move a Lino site to a new server.

restore2preview.py

The file restore2preview.py is in the snapshot of your production project and used by the initdb_from_prod.sh script.

You create this file as a copy of the restore.py file. You will modify it as needed and maintain it until the preview site has become production.

initdb_from_prod.sh

The initdb_from_prod.sh script creates a snapshot of production and then restores that snapshot to preview. It also mirrors media files from prod to preview.

You create this file in the project root of the target site, with the following content, and manually adapt it manually as needed:

#!/bin/bash
# Copyright 2016-2020 Rumma & Ko Ltd
# initialize this project latest production snapshot

set -e

LOGFILE=/var/log/lino/upgrades.log
OLD=/usr/local/django/ann
NEW=/usr/local/django/bert

echo initdb_from_prod.sh was started `date` >> $LOGFILE

echo PART1 : MAKE A SNAPSHOT OF $OLD
cd $OLD
. env/bin/activate
python manage.py dump2py -o snapshot2preview

echo PART2 : MIRROR MEDIA FILES AND SNAPSHOT
OPTS="-a --verbose --delete --delete-excluded --delete-during --times --omit-dir-times --log-file $LOGFILE"

function doit {
    nice rsync $OPTS $OLD/$1 $NEW/
}

doit media
doit snapshot2preview


echo PART3 : RESTORE SNAPSHOT TO $NEW
cd $NEW
. env/bin/activate
python manage.py run snapshot2preview/restore2preview.py --noinput
python manage.py collectstatic --noinput

echo initdb_from_prod.sh finished `date` >> $LOGFILE

Troubleshooting

  • rsync: failed to set times on "...": Operation not permitted (1)

    rsync tries to change the timestamps of directories because that helps detecting changes. But that doesn't work when the file owner is different from the user who runs the migration script. Because it's not allowed to change the timestamp of a file you don't own, even when you have write permission. --> That's why we use the --omit-dir-times option.