API Data Backup and Recovery
APIM Data Backupβ
APIM can restore all data through DB backup/recovery.
MariaDB SQL Backupβ
- Usage: APIM DB
- Description: DB of all data related to APIM such as GW, API, Policy, Document, Developer Portal,etc.
- K8s resource information:
- StatefulSets : apim-mariadb-master
- Pod: apim-mariadb-master-0
- Failure Impact: When MariaDB fails
- APIM console functionals become abnormal
- APIM Developer Portal functionals become abnormal
# Access MariaDB Pod
kubectl -n apim-prd exec -it apim-mariadb-master-0 -c mariadb /bin/bash
# Perform a full SQL dump of MariaDB and save the file in the Pod /tmp directory
mysqldump -uapim -papim apim > /tmp/apim-maria-dump.sql
# Copy the SQL dump to the local environment /tmp directory
kubectl -n apim-prd cp apim-mariadb-master-0:/tmp/apim-maria-dump.sql -c mariadb ./apim-maria-dump.sql
Postgresqlβ
- Usage : APIM User DB
- Description: DB of all data related to User in APIM, such as User, Role, Project, etc.
- About K8s resource
- StatefulSets : statefulset-pgauth
- Pod: statefulset-pgauth-0
- Failure Impact: When MariaDB fails
- APIM console login error
- APIM Tenant Manager console login error
- APIM Developer Portal login error
# Accessing the PostgreSQL Pod Internal and creating an SQL schema dump inside the Pod internal /tmpdirectory, then transferring it to the local /tmp directory
kubectl -n apim-prd exec -it statefulset-pgauth-0 -c pgauth > ./apim-pg-schema.sql -- pg_dump --create -s -U apim -d apim
# Accessing the PostgreSQL Pod Internal and creating an SQL data dump inside the Pod/tmp directory,then transferring it to the local /tmp directory
kubectl -n apim-prd exec -it statefulset-pgauth-0 -c pgauth > ./apim-pg-data.sql -- pg_dump --insert --data-only -U apim -d apim
Check MariaDB, Postgresql Dump Filesβ
# View file list including file size
cd /tmp
ls -alh
# (Optional) View file contents
cat apim-maria-dump.sql
cat apim-pg-schema.sql
cat apim-pg-data.sql
APIM Developer Portal Static Content Filesβ
- Usage: APIM Developer Portal static content files
- Description: All custom files of APIM Developer Portal, including Image, Logo, Favicon, etc.
- About K8s information
- Deployment : deploy-apim-developers-portal-backend
- Pod: deploy-apim-developers-portal-backend-xxxxxx-xxxx
- Failure Impact: When the static content file of the developer portal is deleted
- APIM Developer Portal images, logos, etc. cannot be displayed (Developer Portal
functions are working normally)
# Copy the folder containing the entire static content files of the developer portal to the local machine.
kubectl -n apim-prd cp deploy-apim-developers-portal-backend-xxxxxx-xxxx:/app/src/public ./public-prd
APIM Data Recoveryβ
MariaDBβ
# Copy MariaDB Dump SQL from the local /tmp path to the MariaDB Pod /tmp path
kubectl -n apim-dev cp /tmp/apim-maria-dump.sql apim-mariadb-master-0:/tmp/apim-maria-dump.sql -c mariadb
# Access MariaDB Pod Internals
kubectl -n apim-dev exec apim-mariadb-master-0 -c mariadb /bash
# DB Recovery via MariaDB Pod Dump SQL
mysql -u apim -p apim < /tmp/apim-maria-dump.sql
Postgresqlβ
# Access PostgreSQL Pod
kubectl -n apim-dev exec -it statefulset-pgauth-0 -c pgauth bash
# Delete Postgresql "APIM" Database
dropdb -U postgres apim
# Access Postgresql psql
psql -U postgres
# Postgresql CREATE DATABASE "apim"
CREATE DATABASE apim WITH OWNER apim ENCODING 'UTF8';
# Grant "apim" DATABASE permission to Postgresql "apim" User
GRANT ALL PRIVILEGES ON DATABASE apim TO apim;
# Exit Postgresql
\q
# Restore the database from the PostgreSQL dump files
psql -U apim -d apim -f /tmp/apim-pg-schema.sql
psql -U apim -d apim -f /tmp/apim-pg-data.sql
Proceed with other recovery tasksβ
Force Data Initialization for Kongβ
# Access Kong Pod
kubectl exec --it {gateway pod name} -c proxy /bin/bash -n apim
kong migrations bootstrap
Install the prometheus plugin for Kong Monitoringβ
kubectl -n apim-dev exec --it {gateway pod name} -c fluent-bit /bin/bash
curl -i -X POST localhost:8001/plugins --data '{"name":"prometheus"}' -H "content-type: application/json"
Kong Gateway update actionsβ
Follow-up actions for Kong Gateway due to Redis storage Pod restart (Added: April 4, 2024)
# Dev Environment
kubectl rollout restart deploy/nsmall-gw-kong -n apim
# Prd Environment
kubectl rollout restart deploy/nsmall-prd-gw-kong -n apim