Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nieldw/645f899ec0faca3c1698dd6d471978e7 to your computer and use it in GitHub Desktop.
Save nieldw/645f899ec0faca3c1698dd6d471978e7 to your computer and use it in GitHub Desktop.
Kubernetes Job that restores a Team City backup from a persistent volume
kind: Job
apiVersion: batch/v1
metadata:
name: teamcity-server-backup-restorer
spec:
template:
metadata:
labels:
app: teamcity
type: backup-restorer
spec:
restartPolicy: Never
containers:
- name: teamcity-server
image: jetbrains/teamcity-server:2017.2.4
imagePullPolicy: IfNotPresent
command:
- "/bin/sh"
- "-ec"
- |
set -o nounset
set -o errexit
echo "DOWNLOAD JDBC DRIVER"
mkdir -p "${TEAMCITY_DATA_PATH}"/lib/jdbc
cd "${TEAMCITY_DATA_PATH}"/lib/jdbc
curl -o postgresql-42.2.2.jar https://jdbc.postgresql.org/download/postgresql-42.2.2.jar
echo
echo "RESTORING BACKUP"
cd /backups
BACKUP=$(pwd)/$(ls -t | head -1)
/opt/teamcity/bin/maintainDB.sh restore -F "${BACKUP}"
echo "BACKUP RESTORE COMPLETE"
echo
volumeMounts:
- name: teamcity-datadir
mountPath: /data/teamcity_server/datadir
- name: teamcity-backup
mountPath: /backups
- name: database-properties
mountPath: /data/teamcity_server/datadir/config/database.properties
subPath: database.properties
volumes:
- name: teamcity-datadir
persistentVolumeClaim:
claimName: teamcity-server-pv-claim
- name: teamcity-backup
persistentVolumeClaim:
claimName: teamcity-backup-pv-claim
- name: database-properties
configMap:
name: teamcity-server-database-properties
items:
- key: database.properties
path: database.properties
apiVersion: v1
data:
database.properties: |
connectionProperties.user=teamcity
connectionProperties.password=password
connectionUrl=jdbc:postgresql://teamcity-db:5432/teamcity
kind: ConfigMap
metadata:
name: teamcity-server-database-properties
labels:
app: teamcity
type: backup-restorer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment