How to upgrade H2 database inside Bitbucket Server and Data Center Docker container
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
When upgrading the Bitbucket Server and Data Center installations from versions below 8.8 to versions above 8.8 (for example, from 7.21.x to 8.9.x) that use an H2 database, we need to migrate the on-disk database file format to make it compatible with the new H2 driver version.
The procedure for conversion is given on the page Migrate H2 database from 1.x to 2.1.
Still, with Bitbucket installations inside Docker containers, we need a modified procedure, as explained in this article.
The H2 database is converted mainly when upgrading Bitbucket mirror nodes because they exclusively use the H2 database for storage.
Environment
7.10.0, but it applies to other versions.
Solution
For clarification, here is an explanation of the terms used in this procedure:
- host server - represents the server running Docker software and containers. The meaning of it is "outside the Docker container".
- old Bitbucket - this is a reference to the old Bitbucket version. For example, if we upgrade from 7.21.0 to 8.9.5, this is the version 7.21.0.
- new Bitbucket - this is a reference to the new Bitbucket version. For example, if we upgrade from 7.21.0 to 8.9.5, this is the version 8.9.5.
Part of this procedure to upgrade the H2 database inside the Docker container must be executed on the host server, and part of it inside the new Bitbucket Docker container.
We need one file from the old Bitbucket setup, which we will gather from the downloaded old Bitbucket archive file.
Script snippets below use shell variables that are defined in the first step.
Prepare the host server and gather the required file
We have to execute the steps in this section on the host server.
Define variables:
OLD_BB_VERSION is the version of the old Bitbucket from which we are upgrading.
OLD_BB_CONTAINER is the name of the container that runs the old version of Bitbucket, from which we are upgrading.
NEW_BB_CONTAINER is the name of the container that runs the new version of Bitbucket, to which we are upgrading.OLD_BB_VERSION="7.10.0" OLD_BB_CONTAINER="bitbucket-7.21.0" NEW_BB_CONTAINER="bitbucket-8.9.5"
Shut down the old Bitbucket Docker container:
docker stop ${OLD_BB_CONTAINER}
Download the old Bitbucket archive. We need to extract the h2-*.jar file from it:
wget https://product-downloads.atlassian.com/software/stash/downloads/atlassian-bitbucket-${OLD_BB_VERSION}.tar.gz
Extract h2 processing .jar file:
mkdir -p h2-${OLD_BB_VERSION} tar -xvf \ atlassian-bitbucket-${OLD_BB_VERSION}.tar.gz \ --wildcards \ --strip-components=4 \ -C h2-${OLD_BB_VERSION} \ '*/app/WEB-INF/lib/h2-*.jar'
Copy the extracted file to the new Bitbucket Docker container:
docker cp h2-${OLD_BB_VERSION} ${NEW_BB_CONTAINER}:/tmp/
Convert the H2 database inside the new Bitbucket Docker container
First we have to enter the new Bitbucket Docker container by executing this on the host server:
docker exec -it ${NEW_BB_CONTAINER} /bin/bash
Execute the rest inside the new Bitbucket Docker container:
- Make sure the permissions are correct for the h2-${OLD_BB_VERSION} file. They should be the same as we have in BITBUCKET_HOME
2. Export the JRE_HOME , BITBUCKET_HOME and JAR file path
export JRE_HOME=/opt/java/openjdk/
export BITBUCKET_HOME=/var/atlassian/application-data/bitbucket
export SOURCE_H2_JAR_PATH=/tmp/h2-1.3.176.jar
3. Run the h2-migrate-db-file.sh from there
/opt/atlassian/bitbucket/bin/h2-migrate-db-file.sh
4. List the contents of the shared data directory.
Check if we have a backed-up file and a new one, owned by bitbucket:bitbucket :
ls -l $BITBUCKET_HOME/shared/data/
5. Leave the container:
exit
Restart the new Bitbucket Docker container
We have to restart the Bitbucket node to use the new H2 database.
Execute this on the host server:
docker restart ${NEW_BB_CONTAINER}
After the final restart, the new Bitbucket server running inside the Docker container will be ready.
If you were upgrading the Bitucket Mirror node, the primary Bitbucket node would soon detect the upgraded mirror with the state "SYNCHRONIZED".