Skip to Content
APIGit On-PremiseBackup and restore

Backup and restore

Three things hold your data: the database, the backend’s data volume and the volume of published mock servers. Back them up together, taken at the same time, with your .env file.

Back up

# 1. the database docker compose exec -T postgres sh -c 'pg_dump -U "$POSTGRES_USER" -Fc "$POSTGRES_DB"' > apigit-db.dump # 2. repositories, uploads, the licence and the server keys docker run --rm -v apigit_backend-data:/data:ro -v "$PWD":/backup alpine \ tar czf /backup/apigit-data.tar.gz -C /data . # 3. published mock servers and their saved state docker run --rm -v apigit_mock-data:/data:ro -v "$PWD":/backup alpine \ tar czf /backup/apigit-mocks.tar.gz -C /data . # 4. the settings cp .env apigit-env.backup

The volume name is <project>_backend-data; the project is apigit unless you changed it (docker volume ls shows it). For a consistent copy on a busy server, stop the backend for the two commands: docker compose stop backend, then docker compose start backend.

With your own PostgreSQL, back the database up with your usual tools instead of step 1.

Restore

On a server with the same release and the same .env:

docker compose up -d postgres redis docker compose exec -T postgres sh -c 'pg_restore -U "$POSTGRES_USER" -d "$POSTGRES_DB" --clean --if-exists' < apigit-db.dump docker run --rm -v apigit_backend-data:/data -v "$PWD":/backup alpine \ sh -c 'rm -rf /data/* && tar xzf /backup/apigit-data.tar.gz -C /data' docker run --rm -v apigit_mock-data:/data -v "$PWD":/backup alpine \ sh -c 'rm -rf /data/* && tar xzf /backup/apigit-mocks.tar.gz -C /data' docker compose up -d

Test a restore on a spare machine before you rely on the backup.

Last updated on