9 Backing Up And Restoring the STAP Database
Learn how to backup and restore the Oracle Communications Solution Test Automation Platform (STAP) database.
Topics in this document:
Applicability
- STAP 1.26.1.0.0 and later: Use the script-based logical backup/restore (backup.sh, restore.sh, and so on.) described in this chapter.
- STAP 1.25.x and earlier: Use the legacy PV/NFS folder backup method (tar/zip of the /data/db folder) unless otherwise instructed.
- Migration notes: Backups from 1.25.x are not directly compatible with 1.26.1. For more information, see “Migrating from STAP 1.25.x to 1.26.1”.
Prerequisite (STAP 1.26.1.0.0)
- Ensure tdaas-cntk contains these scripts:
- backup.sh
- config.sh
- restore.sh
- service-port.sh
- values-update.sh
- Grant run permission:
chmod +x *.sh
Note:
You must have administrator access to the cluster/NFS/PV to access /data and run these scripts.Backing Up the STAP Database (STAP 1.26.1.0.0)
To backup STAP database, perform the following steps:
- Update config.sh with your environment values (paths may be relative to the scripts directory or absolute):
- RELEASE_NAME="tdaas-helm"
- NAMESPACE="<your-namespace>"
- CHART_PATH="../helm_chart/taas-tdaas-helm-chart"
- VALUES_FILE="$CHART_PATH/override-values.yaml"
- SERVICE_NAME="tdaas-service"
- Run the following backup script:./backup.sh
- Verify the backup files are created under the mounted path (for example, /data/backups), for example:
- db_bkp_data_only_YYYYMMDD_HHMMSS.sql.gz (data-only backup)
- db_bkp_full_YYYYMMDD_HHMMSS.sql.gz (schema + data + triggers + routines + events)
Restoring the Database (STAP 1.26.1.0.0)
Restore can be performed only after a fresh deployment when the database is empty. To restore the database::
- Copy the data-only backup file to PV/NFS (for example under /data/backups or /data).
- Update config.sh:
- RELEASE_NAME="tdaas-helm"
- NAMESPACE="<your-namespace>"
- CHART_PATH="../helm_chart/taas-tdaas-helm-chart"
- VALUES_FILE="$CHART_PATH/override-values.yaml"
- SERVICE_NAME="tdaas-service"
- Trigger restore::
./restore.sh /data/backups/db_bkp_data_only_YYYYMMDD_HHMMSS.sql.gz - Verify the database has been restored with the TDS APIs. For more information, see REST API Reference for STAP.
Migrating from STAP 1.25.x to 1.26.1.0.0
Backup from 1.25.x is NOT directly compatible with 1.26.1. Use the approach below to generate a compatible backup from the 1.25.x environment.
- Place the following scripts under tdaas-cntk in the STAP 1.25.x environment:
- backup.sh
- config.sh
- restore.sh
- service-port.sh
- values-update.sh
- Update the Helm template in the 1.25.x environment:
- File: helm_chart/taas-tdaas-helm-chart/templates/tdaas-backup-job.yaml
- Apply the job content shown in "tdaas-backup-job.yaml (Migration Helper for STAP 1.25.x)".
- Run the backup job on 1.25.x to produce:
- db_bkp_data_only_YYYYMMDD_HHMMSS.sql.gz (used for restoring into 1.26.1)
- db_bkp_full_YYYYMMDD_HHMMSS.sql.gz (reference or archival)
- Copy the data-only backup to the target 1.26.1 environment PV/NFS path (for example, /data/backups).
- Restore into 1.26.1 using:
./restore.sh /data/backups/db_bkp_data_only_YYYYMMDD_HHMMSS.sql.gz
Note:
The NFS database folder should be exclusively allocated and used by only one TDS microservice at a single point in time.tdaas-backup-job.yaml (Migration Helper for STAP 1.25.x)
Use this job template update in the 1.25.x Helm chart to generate backups compatible with the 1.26.1 restore approach.
{{- if .Values.backup.enable }}
apiVersion: batch/v1
kind: Job
metadata:
name: db-backup-job
labels:
app: db-backup
spec:
template:
spec:
restartPolicy: Never
containers:
- name: db-backup
image: "{{ .Values.image.imageRepository }}{{ .Values.image.imageName }}:{{ .Values.image.imageTag }}"
command: ["/bin/sh", "-c"]
args:
- |
set -e
echo "=== DB Backup Job Starting ==="
# Validate required env vars
if [ -z "$DB_HOST" ] || [ -z "$DB_USER" ] || [ -z "$MYSQL_PWD" ]; then
echo "ERROR: Required DB env vars are missing"
exit 1
fi
# Wait for MySQL
echo "Waiting for MySQL at $DB_HOST:$DB_PORT..."
for i in $(seq 1 10); do
if mysqladmin ping -h "$DB_HOST" -P "$DB_PORT" -u "$DB_USER" --protocol=TCP --silent 2>/dev/null; then
echo "MySQL is reachable."
break
fi
echo "Attempt $i/10 — retrying in 5s..."
sleep 10
if [ "$i" -eq 10 ]; then
echo "ERROR: MySQL not reachable"
exit 1
fi
done
mkdir -p /data/backups
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
# Foreign key safe table order
TABLE_ORDER="environment runtime_scenario simulation_runtime_result \
job execution connection \
runtime_case runtime_case_result runtime_step runtime_step_result \
simulation_event_result simulation_event_failure_result simulation_event_graph_result \
event action log persistent_store runtime_scenario_result search_query_counter search_schema user execution-id"
# Filter only existing tables (KEEP THIS LOGIC)
EXISTING_TABLES=""
for t in $TABLE_ORDER; do
if mysql -h "$DB_HOST" -P "$DB_PORT" -u "$DB_USER" -p"$MYSQL_PWD" \
-e "use $DB_NAME; show tables like '$t';" | grep -q "$t"; then
EXISTING_TABLES="$EXISTING_TABLES $t"
else
echo "WARNING: Table '$t' not found, skipping..."
fi
done
echo "Tables to be dumped: $EXISTING_TABLES"
# ------------------------
# 1 Data-only backup
# ------------------------
DATA_ONLY_FILE="/data/backups/db_bkp_data_only_${TIMESTAMP}.sql.gz"
echo "Starting DATA-ONLY backup..."
mysqldump -h "$DB_HOST" -P "$DB_PORT" -u "$DB_USER" \
--protocol=TCP --single-transaction --quick --lock-tables=false \
--no-create-info "$DB_NAME" $EXISTING_TABLES | gzip > "$DATA_ONLY_FILE"
# ------------------------
# 2 Full backup
# ------------------------
FULL_FILE="/data/backups/db_bkp_full_${TIMESTAMP}.sql.gz"
echo "Starting FULL backup..."
mysqldump -h "$DB_HOST" -P "$DB_PORT" -u "$DB_USER" \
--protocol=TCP --single-transaction --quick --lock-tables=false \
--routines --triggers --events \
"$DB_NAME" $EXISTING_TABLES | gzip > "$FULL_FILE"
echo "Backup completed"
echo "Data-only: $DATA_ONLY_FILE"
echo "Full : $FULL_FILE"
env:
- name: MYSQL_PWD
valueFrom:
secretKeyRef:
name: tdaas-secrets
key: DB_PASSWORD
- name: DB_HOST
value: "{{ .Values.tdaasDB.host }}"
- name: DB_USER
value: "{{ .Values.tdaasDB.username }}"
- name: DB_NAME
value: "{{ .Values.tdaasDB.dbName | default "taas-tdaas-db" }}"
- name: DB_PORT
value: "{{ .Values.tdaasDB.port | default 3306 }}"
volumeMounts:
- mountPath: "/data"
name: tdaas-persistent-storage
volumes:
- name: tdaas-persistent-storage
persistentVolumeClaim:
claimName: tdaas-pvc
imagePullSecrets:
- name: {{ .Values.image.imagePullSecret }}
backoffLimit: 2
activeDeadlineSeconds: 1800
{{- end }}