Restore a Team City backup on a server running in Docker and Kubernetes
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:
- The official Team City docker image, which includes the utility
maintainDB
- A fresh, empty database for the server
- A fresh persistent volume for the server
- A persistent volume containing the backup ZIP archive. If you followed the instructions in the previous post this will already be available
Process
- Do not start the server! The backup has to be restored before the first run
- Create the database and the PersistentVolumeClaim for the server’s data directory
- Prepare the PersistentVolumeClaim holding the backup
- Populate the ConfigMap with the correct
database.properties
file - Start the restore Job
- 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.