Restore a Team City backup on a server running in Docker and Kubernetes

Niel de Wet
2 min readJun 6, 2018

--

Photo by Esteban Castle on Unsplash

In the previous post I showed how to use a Kubernetes CronJob to preform regular backups of a Team City server. In this post I will show how to use a Kubernetes Job to restore the backup.

Restoring a backup for a traditional install is pretty well documented and easy to do. I found no documentation for doing it with a Docker installation. Thanks to Stéphane Erbrech for sharing how he did it just with Docker.

Requirements

This approach relies on the following:

  1. The official Team City docker image, which includes the utility maintainDB
  2. A fresh, empty database for the server
  3. A fresh persistent volume for the server
  4. A persistent volume containing the backup ZIP archive. If you followed the instructions in the previous post this will already be available

Process

  1. Do not start the server! The backup has to be restored before the first run
  2. Create the database and the PersistentVolumeClaim for the server’s data directory
  3. Prepare the PersistentVolumeClaim holding the backup
  4. Populate the ConfigMap with the correct database.properties file
  5. Start the restore Job
  6. Start the freshly restored Team City server!

Putting it all together

Database

Create an empty database. In this example we’ll use a PostgreSQL database, reachable at teamcity-db:5432.

PersistentVolumeClaims

Create new a PersistentVolumeClaim for the server’s data directory. Also, create, if you have not yet done so, another one which will hold the backup. In our example the names of these claims are teamcity-server-pv-claim and teamcity-backup-pv-claim, respectively.

Database connection properties

The restoration utility requires a file called database.properties holding the connection details. We mount a ConfigMap containing this file and place it in the default location, /datadir/config/database.properties.

Job and ConfigMap manifests

With everything in place we can now define our Kubernetes manifests:

What is happening?

The database.properties file is mounted from the ConfigMap along with the server’s data directory and the volume holding the backups.

The shell script in the Job’s command first downloads a PostgreSQL database driver before locating the latest backup by modification time and running the maintainDB.sh script to restore the server from backup.

Once the Job has run to completion you can start the Team City server by mounting the same ConfigMap and the data directory’s PersistentVolumenClaim.

--

--

No responses yet