Migrate and Upgrade
Steps to restore the CollectionSpace database files from the old server onto the new server. I am using v4.1 on the old server and v5.2 on the new server.
CollectionSpace should first be installed on the new server and the tenant āyour_tenant' configured there. For the tenant I use the profile FCART for fine and contemporary art. The installer and tenant creation process and are described here:
CollectionSpace Current Documentation
https://collectionspace.atlassian.net/wiki/spaces/DOC/pages/2593661043 Ā
The instructions for creating the new tenant specify that the fileĀ /home/cspace/collectionspace-source/application/tenant.properties
Ā needs to be edited for these values:
template.tenant.shortname
tenant.shortname
tenant.id
tenant.internet.domain
For the tenant use:
template.tenant.shortname=fcart
tenant.shortname=your_tenant
tenant.id=110
tenant.internet.domain=your_domain
After installation the newĀ tenant should be available here: http://ip_address:8180/cspace/your_tenant/
Itās important to log on to your new tenant and create at least one media record. This will establish the media directories on the new server.
Overall the steps to migrate and upgrade are:
Backup and restore roles
Backup and restore the cspace database
Backup and restore the nuxeo database and data files
Backup and restore your tenant database
Fix-up permissions and ownership in the three databases
Run 4.1 upgrade sql script in cspace database
Ant undeploy deploy
Ant import
This task describes how to connect to the database servers and to backup databases from the source and to restore databases at the target. The termĀ source serverĀ is defined as the existing cspace server you are moving from, and the termĀ target serverĀ is defined as the new cspace server you are moving into. The database technology isĀ postgresql
Ā and referred to asĀ postgres
. The commandĀ psql
Ā connects to the database server and allowsĀ postgres
Ā specific work to be done with more commands. The linuxĀ bash
Ā environment is used inĀ ssh
Ā sessions connected to the source and target servers from the operator workstation (that's you and your computer) and is where you run commands on the source and target. User accounts withĀ sudo
Ā privilege includeĀ root
Ā plus any accounts you added to the groupĀ sudo
.
The following steps are for the target server. (This is after you have installed your new tenant there and created at least one media record to validate the installation worked.)
Start a session as user withĀ
sudo
Ā privilege to the target server usingĀssh
.Run the commandĀ
sudo su postgres
Ā to change to the userĀpostgres
Ā which is allowed to connect to theĀpostgres
Ā environment.Run the commandĀ
cd ~
Ā to change to the home directory.Run theĀ
psql
Ā command to connect toĀpostgres
.Inside theĀ
psql
Ā prompt run the commandĀ\l
Ā to list the databases so you are familiar with them.Inside the psql prompt run theĀ
\du
Ā to list the user roles so you are familiar with them.
The following steps are done on the source server
Create backup files.
Create the database backup from the source server which will be used to restore the database at the target. At the source server in theĀ
ssh
Ā session change to user postgres with the commandĀsudo su postgres
Ā then commandĀcd ~
Ā to change to the home directory. Run the command:pg_dump -Ft -f./yourtenant_domain.tar yourtenant_domain
This created the backup fileĀ
yourtenant_domain.tar
Ā in the current directory in a compressed format for the databaseĀyourtenant_domain
. The current directory for userĀpostgres
Ā is /var/lib/postgresql/Repeat the
pg_dump
for databasesnuxeo_default
andcspace_default
. They may be named differently on your source server.Create the backup of the roles needed from the source environment that will be needed to restore the database at the target. Still at the source server run the command:
Exit the user sessionĀ
postgres
. This created the backup fileĀdump_roles.bak
Ā in the current directory.Create a new folder in your home directory to receive the
nuxeo
media files. Copy the files atĀ$CATALINA_HOME/nuxeo-server/data/yourtenant_domain/data/
Ā into this new folder.This backed up the media files.
The following steps are to copy the files to the target server.
The exact steps to accomplish the copy are not described here. It may be easiest to copy files from the source server to the your workstation and then from that workstation to the target server.
Copy theĀ
yourtenant_domain.tar
Ā andcspace
andnuxeo
database backup files to the target server directoryĀ/var/lib/postgresql/
Copy the media backup folder toĀ
/usr/local/share/apache-tomcat-8.5.40/nuxeo-server/data/yourtenant/data/
Here is an example copy command from the root account at the following directory:Ā
root@yourserver:~/20191124backupCatalina/nuxeo-server/data/yourtenant_domain/data#Ā
cp ./* /usr/local/share/apache-tomcat-8.5.40/nuxeo-server/data/yourtenant/data/ -r
Follow this with the command to fix the ownership of the data files on the target server:
chown cspace:cspace /usr/local/share/apache-tomcat-8.5.40/nuxeo-server/data/yourtenant/data/* --recursive
Restore the postgres roles at the target server. Use command
sudo su postgres
and thencd ~
to go to the home directory of thepostgres
user. Start apsql
session. Ā Run the commandĀ\i DUMPROLES.BAK
which will process the file previously copied to that directory. Existpsql
with command\q
Drop the databases on the target server and in prepararation to create blank databases to accept the source databases that you are restoring. The commands to do this are:
sudo su postgres
to change to the database user, andpsql
to enter the postgresql environment. Then issue three psql commandsdrop database cspace_default; drop database nuxeo_default; drop database yourtenant_default;
The semicolon is part of the command.Create the databases in
psql
: Three commands again:create database cspace_default; create database nuxeo_default; create database yourtenant_default;
Fix-up the permissions with theĀ
psql
Ā commandĀGRANT
. Notice we omit thecspace_default
as it appears to use different default permissions and not need any fix-up. The command reference is here:Ā https://www.postgresql.org/docs/current/sql-grant.htmlALTER DATABASE nuxeo_default OWNER TO nuxeo_default;
ALTER DATABASE yourtenant_default OWNER TO nuxeo_default;
GRANT TEMP ON DATABASE nuxeo_default TO nuxeo_default;
GRANT TEMP ON DATABASE yourtenant_default TO nuxeo_default;
GRANT CONNECT ON DATABASE nuxeo_default TO reader_default;
GRANT CONNECT ON DATABASE yourtenant_default TO reader_default;
Restore the databases
nuxeo_default
,yourtenant_default
,cspace_default
at the target withĀbash
Ā and userĀpostgres
. These arebash
and notpsql
commands. Your will need to refine the data filenames for your case. (You created these data files at the source server and copied them to the target.)Āpg_restore --clean --dbname=nuxeo_default nuxeo.tar
pg_restore --clean --dbname=yourtenant_default yourtenant.tar
pg_restore --clean --dbname=cspace_default cspace.tar
Upgrade the new cspace_default database from v4.1, so as user
postgres
inbash
download the upgrade script and inpsql
run the upgrade script as follows.In
bash
in the home directory forpostgres
run the following command (note: if you receive āNo such file or directoryā you will need to carefully type it intobash
because it doesnāt seem to copy and paste correctly).wgetĀ https://raw.githubusercontent.com/cspace-deployment/Tools/master/scripts/db/upgrade_4.1_to_5.0.sql
In
psql
connect to databasecspace_default
with command\c cspace_default
and run the upgrade scriptĀ with command:\i upgrade_4.1_to_5.0.sql
Fix up the schema permissions.The nuxeo_default db restore leaves many items owned by the old user 'nuxeo' and not the current 'nuxeo_default'. Here are
bash
(notpsql
) scripts to fix the ownership.Ā
In
bash
exitpostgres
and change userssudo su cspace
. Go to the directory~/collectionspace-source/services
and run these commands (you ran them previously to deploy your new tenant). Both commands should complete with the messageBUILD SUCCESSFUL
.ant undeploy deploy
ant import
Start up CollectionSpace (done as user
cspace
with command$CSPACE_JEESERVER_HOME/bin/startup.sh
) Validate your tenant. The records should all be migrated and upgraded.
Useful commands in psql
include:
\l to list the databases
\q to exit psql
\c to connect to a database
\dt to display tables in the connected database
\du to display users in the connected database
\ds to display sequences in the connected database
\? to show a list of commands (itās a long list and you will see the
:
so use the up or down arrow to scroll and typeq
to exit the list)
Validation of the top five tables by size can be done with this code in psql
first connecting to a database with \c yourtenant_default
or \c nuxeo_default
or \c cspace_default
SELECT nspname || '.' || relname AS "relation", pg_size_pretty(pg_total_relation_size(C.oid)) AS "total_size" FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) WHERE nspname NOT IN ('pg_catalog', 'information_schema') AND C.relkind <> 'i' AND nspname !~ '^pg_toast' ORDER BY pg_total_relation_size(C.oid) DESC LIMIT 5;
Basic troubleshooting: Check the logs. Slow down, do one operation at a time and check the logs at /usr/local/share/apache-tomcat-8.5.40/logs
. Focus there onĀ cspace-services.log
and catalina.out
.
Is the application startup healthy? Compare it to a pristine startup log.
Can the services be called ? Compare a successful call to an unsuccessful call.
Try probing this logon service:
curl -i http://localhost:8180/cspace-services/collectionobjects -u admin@core.collectionspace.org:Administrator
curl -i http://localhost:8180/cspace-services/collectionobjects -u admin@core.collectionspace.org:Administrator
Ā