Commit af57958f authored by Piotr Gawron's avatar Piotr Gawron
Browse files

upgrade from version before 12.1.0 is not possible using debian package

parent c0007506
Pipeline #39892 passed with stage
in 26 minutes and 7 seconds
minerva (16.0.0~alpha.2) stable; urgency=medium
* Backward incompatibility: debian package cannot be upgraded from version
prior to 12.1.0 (#1464)
* Small improvement: homomultimer information is provided in API (#1468)
-- Piotr Gawron <piotr.gawron@uni.lu> Fri, 26 Mar 2021 10:00:00 +0200
......
......@@ -9,23 +9,15 @@ versionCompLt() {
[ "$1" = "$2" ] && return 1 || versionCompLte $1 $2
}
# file with bash code generating DB schema diffs for different versions
dbschemadiff=management_scripts/db_schema_and_diff.sh
#Where source file of the debian package should be placed
SRC_DIR=debian/src
#File that should be deployed on tomcat
TOMCAT_FILE=web/target/*.war
#Directory with database schema
DB_SCHEMA_DIR=persist/src/main/resources/db/migration/postgres
ROOT_DIR=`pwd`
# where dn script files should be stored on the debian system
DB_SCRIPT_DIR="\/usr\/share\/minerva\/schema"
LOG_FILE="\/var\/log\/minerva-install.log"
#clean build directories
......@@ -52,20 +44,9 @@ cp debian/scripts/common.sh $SRC_DIR/
#copy changelog file
cp CHANGELOG $ROOT_DIR/debian/template/changelog
# set $versions and $current_version; generate upgrade scripts in SRC_DIR
DBSCRIPT_DEST_DIR=$SRC_DIR
MAX_DB_VERSION_FOR_MIGRTION=12.1.0~alpha
source $dbschemadiff
current_version=`cat CHANGELOG |grep minerva |head -1 | cut -f2 -d'(' | cut -f1 -d')'`
echo "Current version: " $current_version
echo "Flyway was introduced in version: " $MAX_DB_VERSION_FOR_MIGRTION
#------------------------------------------
# Now we have all db schema diff files. Let's start preparing
# debian package
#------------------------------------------
#dh_make requires directory name to be like <package>-<version>
# this points to the directory
......@@ -92,11 +73,6 @@ find -name '*.ex' ! -name 'minerva*' -type f -exec rm -f {} +
sed -i "s/__CURRENT_VERSION__/$current_version/g" common.sh
sed -i "s/__LOG_FILE__/$LOG_FILE/g" common.sh
#__DB_SCRIPT_DIR__ in our scripts points to place where db schema files are placed
#in the filesystem where package is installed
sed -i "s/__DB_SCRIPT_DIR__/$DB_SCRIPT_DIR/g" common.sh
sed -i "s/__MAX_DB_VERSION_FOR_MIGRTION__/$MAX_DB_VERSION_FOR_MIGRTION/g" common.sh
sed -i -e "1r common.sh" debian/config
sed -i -e "1r common.sh" debian/postinst
......@@ -107,14 +83,6 @@ sed -i -e "1r common.sh" debian/prerm
#put scripts into $DB_SCRIPT_DIR (it's a bit different than varaiable because it's not
#escaped
echo db_0_to_$MAX_DB_VERSION_FOR_MIGRTION".sql" /usr/share/minerva/schema >> debian/install
for version in ${versions[*]}
do
echo db_"$version"_to_$MAX_DB_VERSION_FOR_MIGRTION".sql" /usr/share/minerva/schema >> debian/install;
done
#set proper architecture
arch=`dpkg --print-architecture`
echo "Architecture: $arch" >>debian/control
......
......@@ -4,9 +4,6 @@ log(){
}
LOG_FILE="__LOG_FILE__"
DB_SCRIPT_DIR="__DB_SCRIPT_DIR__"
MAX_DB_VERSION_FOR_MIGRTION="__MAX_DB_VERSION_FOR_MIGRTION__"
#new (current) version of the package
CURRENT_VERSION="__CURRENT_VERSION__"
#if we update package then this will be the old version of the package
......
#! /bin/bash
./map_viewer_dump.sh
./postgres_dump.sh
#./map_images.sh
#! /bin/bash
BACKUP_FILE="/opt/backup/backup.tar.gz"
BACKUP_DIR="/tmp/backup/"
CATALINA_HOME="/var/lib/tomcat7"
rm -f $BACKUP_FILE
rm -rdf $BACKUP_DIR
mkdir -p $BACKUP_DIR/tmp
cp $CATALINA_HOME/webapps/*.war "$BACKUP_DIR/tmp" 2>/dev/null
if [ -d "$CATALINA_HOME/webapps/map_images" ]
then
cd $CATALINA_HOME/webapps/
tar -zcf $BACKUP_DIR/tmp/map_images.tar.gz map_images
fi
export PGPASSWORD="123qweasdzxc"
pg_dump -U map_viewer map_viewer | gzip > "$BACKUP_DIR/tmp/map_viewer_db.gz"
cd $BACKUP_DIR/tmp
tar -zcf $BACKUP_FILE *
chown backup $BACKUP_FILE
cd /
rm -rf $BACKUP_DIR/tmp
# shell snippet which extracts all available MINERVA versions from
# subdirectories available in DB_SCHEMA_DIR (typically
# `persist/src/db`) and generates database upgrade scripts (diff
# files)
# Precondition: the following variables have to be correctly initialised
# * DB_SCHEMA_DIR set to the directory containing database initialisation and upgrade sql commands
# * DBSCRIPT_DEST_DIR set to the directory that will be populated with database upgrade scripts
# * MAX_DB_VERSION_FOR_MIGRTION set to the max version number that should be used for generating migration scripts; further version will be managed by flyway
# Postcondition:
# * versions is set to the available MINERVA versions (bash array)
# * DBSCRIPT_DEST_DIR contains script to initialise the database from any version to the current version
#this variable will contain all available versions of the package
versions=();
#find all available versions
versionCompLte() {
[ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]
}
versionCompLt() {
[ "$1" = "$2" ] && return 1 || versionCompLte $1 $2
}
for version in `ls "$DB_SCHEMA_DIR" | sort -V`;
do
if [ -d "$DB_SCHEMA_DIR/$version" ]
then
if versionCompLt $version $MAX_DB_VERSION_FOR_MIGRTION
then
versions+=($version);
fi
fi
done
#--------------------------------------
# GENERATE DB schemas and diff files
#--------------------------------------
for version_A in ${versions[*]}
do
touch $DBSCRIPT_DEST_DIR/db_${version_A}_to_${MAX_DB_VERSION_FOR_MIGRTION}.sql
done
#last version (used for generating db diff files)
for version_A in ${versions[*]}
do
#main update file (used to create this version - it's a diff
#between base.sql and last version not managed by flyway)
update_file="$DBSCRIPT_DEST_DIR/db_0_to_${MAX_DB_VERSION_FOR_MIGRTION}.sql";
#now iterate through all versions
for file in `ls "$DB_SCHEMA_DIR/$version_A" | sort -V`;
do
if [ -f "$DB_SCHEMA_DIR/$version_A/$file" ]
then
#add db schema diff to last version not managed by flyway
printf "\n\n-- UPDATE $version_A/$file\n\n" >> "$update_file";
cat "$DB_SCHEMA_DIR/$version_A/$file" >> "$update_file";
#and now iterate again through all versions to add diffs
#between previous versions and current one
for version_B in ${versions[*]}
do
#update from version_B should contain all db changes that appeared
#after #version_B (so version_A must be later)
if versionCompLt $version_B $version_A
then
upd_file="$DBSCRIPT_DEST_DIR/db_${version_B}_to_${MAX_DB_VERSION_FOR_MIGRTION}.sql";
printf "\n\n-- UPDATE $version_A/$file\n\n" >> "$upd_file";
cat "$DB_SCHEMA_DIR/$version_A/$file" >> "$upd_file";
fi
done
fi
done
done
#! /bin/bash
echo "Dump of images..."
cd $CATALINA_HOME/webapps/
tar -zcf $RESTORE_DIR/map_images.tar.gz map_images
echo "Done"
#! /bin/bash
echo "Dump of MapViewer war file"
TIMESTAMP=$(date +"%F")
BACKUP_DIR="$BACKUP_DIR/$TIMESTAMP"
mkdir -p "$BACKUP_DIR/map_viewer"
cp $CATALINA_HOME/webapps/MapViewer.war "$BACKUP_DIR/map_viewer/"
cp $CATALINA_HOME/webapps/MapViewer.war $RESTORE_DIR
echo "Done"
#! /bin/bash
echo "Dump of postgres DB..."
TIMESTAMP=$(date +"%F")
BACKUP_DIR="$BACKUP_DIR/$TIMESTAMP"
mkdir -p "$BACKUP_DIR/postgres"
pg_dump -U map_viewer map_viewer | gzip > "$BACKUP_DIR/postgres/map_viewer.gz"
cp "$BACKUP_DIR/postgres/map_viewer.gz" $RESTORE_DIR
echo "Done"
#!/bin/bash
function print_help {
echo "Usage: ";
echo " $0 [params]";
echo "";
echo "If no params are set then script restores minerva framework from the data put manually in the \$RESTORE_DIR directory. To run script properly following environment variables must be set: ";
echo " \$CATALINA_HOME Apache Tomcat installation directory";
echo " \$RESTORE_DIR directory with restore point (files that should override current configuration)";
echo " \$BACKUP_DIR backup directory - place where all backup files are located";
echo "";
echo "";
echo "Available params: ";
echo " --help prints this help";
echo " --list-points prints list of available restore time points";
echo " --restore-point=POINT defines point from which system should be restored (if POINT=LAST then latest restore point is used)";
echo "";
echo "Current configuration:"
echo " CATALINA_HOME: $CATALINA_HOME"
echo " RESTORE_DIR: $RESTORE_DIR"
echo " BACKUP_DIR: $BACKUP_DIR"
}
function print_list {
ls -c1 $BACKUP_DIR
}
function restore {
point=`echo $1| cut -f2 -d"="`
if [[ $point == LAST ]]
then
point=`ls -c1 $BACKUP_DIR|head -1`
fi
cp $BACKUP_DIR/$point/map_viewer/MapViewer.war $RESTORE_DIR
cp $BACKUP_DIR/$point/postgres/map_viewer.gz $RESTORE_DIR
}
if [ -z "$CATALINA_HOME" ]
then
echo "\$CATALINA_HOME is not set"
exit
fi
if [ -z "$RESTORE_DIR" ]
then
echo "\$RESTORE_DIR is not set"
exit
fi
if [ -z "$BACKUP_DIR" ]
then
echo "\$BACKUP_DIR is not set"
exit
fi
for var in "$@"
do
if [ "$var" == "--list-points" ]
then
print_list
exit
fi
if [ "$var" == "--help" ]
then
print_help
exit
fi
if [[ $var == "--restore-point"* ]]
then
restore $var
fi
done
echo "Shutdown tomcat... "
while [ `ps aux |grep apache-tomcat |wc -l` -ne "1" ]
do
$CATALINA_HOME/bin/shutdown.sh
echo "waiting for tomcat to shut down"
sleep 1
ps aux |grep apache-tomcat |wc -l
done
if [ -f $RESTORE_DIR/map_viewer.gz ]
then
echo "Gzipped db found"
cd $RESTORE_DIR
gzip -d map_viewer.gz
mv map_viewer map_viewer.sql
fi
if [ -f $RESTORE_DIR/map_images.tar.gz ]
then
echo "Images archive found..."
mv $RESTORE_DIR/map_images.tar.gz $CATALINA_HOME/webapps/
cd $CATALINA_HOME/webapps/
tar --checkpoint=1024 -zxf map_images.tar.gz
rm map_images.tar.gz
fi
if [ -f $RESTORE_DIR/img.tar.gz ]
then
echo "Images archive found..."
mv $RESTORE_DIR/img.tar.gz $CATALINA_HOME/webapps/map_images/
cd $CATALINA_HOME/webapps/map_images/
tar --checkpoint=1024 -zxf img.tar.gz
rm img.tar.gz
fi
if [ -f $RESTORE_DIR/map_viewer.sql ]
then
echo "Drop db..."
dropdb -U map_viewer -h localhost map_viewer
echo "Create db..."
createdb -U map_viewer -h localhost map_viewer
psql -U map_viewer -h localhost -f $RESTORE_DIR/map_viewer.sql map_viewer
rm $RESTORE_DIR/map_viewer.sql
fi
if [ -f $RESTORE_DIR/MapViewer.war ]
then
echo "New MapViewer.war found"
rm -rf $CATALINA_HOME/webapps/MapViewer
rm -rf $CATALINA_HOME/work/Catalina
mv $RESTORE_DIR/MapViewer.war $CATALINA_HOME/webapps/
fi
echo "Turn on tomcat..."
$CATALINA_HOME/bin/startup.sh
#!/bin/bash
if [ -z "$CATALINA_HOME" ]
then
echo "\$CATALINA_HOME is not set"
exit
fi
if [ -z "$RESTORE_DIR" ]
then
echo "\$RESTORE_DIR is not set"
exit
fi
if [ -z "$BACKUP_DIR" ]
then
echo "\$BACKUP_DIR is not set"
exit
fi
echo "Shutdown tomcat... "
while [ `ps aux |grep apache-tomcat |wc -l` -ne "1" ]
do
$CATALINA_HOME/bin/shutdown.sh
echo "waiting for tomcat to shut down"
sleep 1
ps aux |grep apache-tomcat |wc -l
done
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment