Skip to main content

Backups API

The Backups API provides endpoints for creating, managing, and restoring backups. You can execute manual backups, list backup history, verify integrity, preview contents, and restore data.

Endpoints Overview

MethodEndpointDescription
POST/backupsExecute a backup
GET/backups/project/:projectIdList backups for a project
GET/backups/:projectId/:backupIdGet backup details
POST/backups/restoreRestore from backup
GET/backups/:projectId/:backupId/verifyVerify backup integrity
GET/backups/:projectId/:backupId/previewPreview backup contents
GET/backups/:projectId/diffCompare two backups
DELETE/backups/:projectId/:backupIdDelete a backup

Execute Backup

Create a new backup for a project.

POST /api/v1/backups
Authorization: Bearer YOUR_TOKEN
X-Organization-Id: YOUR_ORG_ID
Content-Type: application/json

{
"projectId": "proj_abc123",
"type": "full",
"collections": ["users", "orders"],
"includeSubcollections": true,
"includeAuth": false,
"storageDestinationId": "storage_xyz789",
"compression": "brotli",
"encrypt": true
}

Request Body:

FieldTypeRequiredDefaultDescription
projectIdstringYes-Project to backup
typestringNofullfull or incremental
collectionsarrayNoAllCollections to backup
includeSubcollectionsbooleanNotrueInclude subcollections
includeAuthbooleanNofalseInclude Firebase Auth users
storageDestinationIdstringNoDefaultStorage destination
compressionstringNobrotlibrotli, gzip, or none
encryptbooleanNotrueEnable encryption

Response:

{
"success": true,
"data": {
"id": "bkp_xyz789",
"projectId": "proj_abc123",
"type": "full",
"status": "pending",
"collections": ["users", "orders"],
"createdAt": "2024-01-15T10:00:00Z"
}
}

Backup Status Flow

pending → running → compressing → encrypting → uploading → completed
└→ failed

List Backups

Get all backups for a project.

GET /api/v1/backups/project/:projectId
Authorization: Bearer YOUR_TOKEN
X-Organization-Id: YOUR_ORG_ID

Query Parameters:

ParameterTypeDefaultDescription
pageinteger1Page number
limitinteger20Items per page (max 100)
statusstring-Filter: completed, failed, pending, running
typestring-Filter: full, incremental, pitr
fromstring-ISO 8601 start date
tostring-ISO 8601 end date

Response:

{
"success": true,
"data": [
{
"id": "bkp_xyz789",
"projectId": "proj_abc123",
"type": "full",
"status": "completed",
"documentsCount": 15000,
"collectionsCount": 12,
"originalSize": 45000000,
"compressedSize": 6200000,
"duration": 45,
"createdAt": "2024-01-15T10:00:00Z",
"completedAt": "2024-01-15T10:00:45Z"
}
],
"meta": {
"page": 1,
"limit": 20,
"total": 42,
"totalPages": 3
}
}

Get Backup Details

Retrieve detailed information about a specific backup.

GET /api/v1/backups/:projectId/:backupId
Authorization: Bearer YOUR_TOKEN
X-Organization-Id: YOUR_ORG_ID

Response:

{
"success": true,
"data": {
"id": "bkp_xyz789",
"projectId": "proj_abc123",
"type": "full",
"status": "completed",
"collections": [
{ "name": "users", "documentsCount": 10000, "size": 30000000 },
{ "name": "orders", "documentsCount": 5000, "size": 15000000 }
],
"includeSubcollections": true,
"includeAuth": false,
"documentsCount": 15000,
"collectionsCount": 2,
"originalSize": 45000000,
"compressedSize": 6200000,
"compressionRatio": 0.86,
"compression": "brotli",
"encrypted": true,
"checksum": "sha256:a1b2c3d4e5f6...",
"storageDestination": {
"id": "storage_xyz789",
"type": "s3",
"bucket": "my-backup-bucket",
"path": "backups/proj_abc123/bkp_xyz789.fbk"
},
"duration": 45,
"createdAt": "2024-01-15T10:00:00Z",
"completedAt": "2024-01-15T10:00:45Z",
"createdBy": {
"id": "user_abc123",
"email": "user@example.com"
}
}
}

Restore from Backup

Restore data from a backup to a project.

POST /api/v1/backups/restore
Authorization: Bearer YOUR_TOKEN
X-Organization-Id: YOUR_ORG_ID
Content-Type: application/json

{
"backupId": "bkp_xyz789",
"projectId": "proj_abc123",
"targetProjectId": "proj_def456",
"collections": ["users"],
"mergeMode": "overwrite",
"dryRun": false
}

Request Body:

FieldTypeRequiredDefaultDescription
backupIdstringYes-Backup to restore from
projectIdstringYes-Source project ID
targetProjectIdstringNoSameTarget project (cross-project restore)
collectionsarrayNoAllCollections to restore
mergeModestringNooverwriteoverwrite, skip_existing, merge
dryRunbooleanNofalsePreview without writing

Response:

{
"success": true,
"data": {
"restoreJobId": "restore_abc123",
"status": "pending",
"backupId": "bkp_xyz789",
"targetProjectId": "proj_def456",
"collections": ["users"],
"mergeMode": "overwrite",
"createdAt": "2024-01-15T11:00:00Z"
}
}

Get Restore Status

GET /api/v1/backups/restore/:restoreJobId
Authorization: Bearer YOUR_TOKEN
X-Organization-Id: YOUR_ORG_ID

Response:

{
"success": true,
"data": {
"id": "restore_abc123",
"status": "completed",
"progress": 100,
"documentsRestored": 10000,
"collectionsRestored": 1,
"errors": [],
"startedAt": "2024-01-15T11:00:00Z",
"completedAt": "2024-01-15T11:02:30Z"
}
}

Verify Backup Integrity

Verify that a backup is valid and can be restored.

GET /api/v1/backups/:projectId/:backupId/verify
Authorization: Bearer YOUR_TOKEN
X-Organization-Id: YOUR_ORG_ID

Response:

{
"success": true,
"data": {
"valid": true,
"checks": {
"fileExists": true,
"checksumValid": true,
"decryptable": true,
"decompressable": true,
"structureValid": true
},
"verifiedAt": "2024-01-15T11:00:00Z"
}
}

Verification Failure

{
"success": true,
"data": {
"valid": false,
"checks": {
"fileExists": true,
"checksumValid": false,
"decryptable": null,
"decompressable": null,
"structureValid": null
},
"error": "Checksum mismatch: expected sha256:abc123, got sha256:def456",
"verifiedAt": "2024-01-15T11:00:00Z"
}
}

Preview Backup Contents

Browse the contents of a backup without restoring.

GET /api/v1/backups/:projectId/:backupId/preview
Authorization: Bearer YOUR_TOKEN
X-Organization-Id: YOUR_ORG_ID

Query Parameters:

ParameterTypeDefaultDescription
collectionstring-Specific collection to preview
limitinteger10Documents per collection (max 100)
pathstring-Document path to preview

Response (Collection List):

{
"success": true,
"data": {
"collections": [
{
"name": "users",
"documentsCount": 10000,
"sampleDocuments": [
{
"id": "user_1",
"data": {
"email": "user1@example.com",
"name": "John Doe",
"createdAt": "2024-01-01T00:00:00Z"
}
}
]
}
]
}
}

Response (Specific Document):

GET /api/v1/backups/:projectId/:backupId/preview?path=users/user_1
{
"success": true,
"data": {
"path": "users/user_1",
"document": {
"id": "user_1",
"data": {
"email": "user1@example.com",
"name": "John Doe",
"createdAt": "2024-01-01T00:00:00Z"
},
"subcollections": ["settings", "notifications"]
}
}
}

Compare Backups (Diff)

Compare two backups to see differences.

GET /api/v1/backups/:projectId/diff
Authorization: Bearer YOUR_TOKEN
X-Organization-Id: YOUR_ORG_ID

Query Parameters:

ParameterTypeRequiredDescription
backup1stringYesFirst backup ID
backup2stringYesSecond backup ID
collectionstringNoSpecific collection to compare

Response:

{
"success": true,
"data": {
"backup1": {
"id": "bkp_older",
"createdAt": "2024-01-14T10:00:00Z"
},
"backup2": {
"id": "bkp_newer",
"createdAt": "2024-01-15T10:00:00Z"
},
"summary": {
"added": 150,
"modified": 45,
"deleted": 10,
"unchanged": 9795
},
"collections": {
"users": {
"added": 100,
"modified": 25,
"deleted": 5
},
"orders": {
"added": 50,
"modified": 20,
"deleted": 5
}
},
"changes": [
{
"type": "added",
"collection": "users",
"documentId": "user_new1"
},
{
"type": "modified",
"collection": "users",
"documentId": "user_123",
"fields": ["email", "updatedAt"]
},
{
"type": "deleted",
"collection": "users",
"documentId": "user_old1"
}
]
}
}

Delete Backup

Permanently delete a backup from storage.

DELETE /api/v1/backups/:projectId/:backupId
Authorization: Bearer YOUR_TOKEN
X-Organization-Id: YOUR_ORG_ID

Response:

{
"success": true,
"message": "Backup deleted successfully"
}
Permanent Deletion

Deleted backups cannot be recovered. Ensure you have alternative backups before deleting.

Backup Object

FieldTypeDescription
idstringUnique backup ID
projectIdstringSource project ID
typestringfull, incremental, or pitr
statusstringCurrent status
collectionsarrayBacked up collections with stats
documentsCountintegerTotal documents
collectionsCountintegerTotal collections
originalSizeintegerSize before compression (bytes)
compressedSizeintegerSize after compression (bytes)
compressionRationumberCompression ratio (0-1)
compressionstringCompression algorithm
encryptedbooleanWhether backup is encrypted
checksumstringSHA-256 checksum
storageDestinationobjectStorage location details
durationintegerBackup duration (seconds)
createdAtstringISO 8601 timestamp
completedAtstringISO 8601 timestamp
createdByobjectUser who initiated backup

Error Responses

Backup Not Found

{
"success": false,
"error": {
"code": "BACKUP_NOT_FOUND",
"message": "Backup 'bkp_xxx' not found"
}
}

Backup In Progress

{
"success": false,
"error": {
"code": "BACKUP_IN_PROGRESS",
"message": "A backup is already in progress for this project"
}
}

Restore Failed

{
"success": false,
"error": {
"code": "RESTORE_FAILED",
"message": "Failed to restore backup",
"details": {
"reason": "Insufficient permissions on target project",
"documentsRestored": 5000,
"failedAt": "users/user_5001"
}
}
}

Webhook Events

The following webhook events are triggered for backup operations:

EventDescription
backup.startedBackup job started
backup.progressBackup progress update (25%, 50%, 75%)
backup.completedBackup completed successfully
backup.failedBackup failed
restore.startedRestore job started
restore.completedRestore completed successfully
restore.failedRestore failed

See Webhooks for event payload details.