Skip to main content

PITR API

The Point-in-Time Recovery (PITR) API enables continuous data protection by capturing every change to your Firestore database. This allows you to restore data to any specific moment in time.

Endpoints Overview

MethodEndpointDescription
POST/pitr/enableEnable PITR for a project
POST/pitr/:projectId/disableDisable PITR
POST/pitr/:projectId/pausePause PITR capture
POST/pitr/:projectId/resumeResume PITR capture
GET/pitr/:projectId/configGet PITR configuration
PATCH/pitr/:projectId/configUpdate PITR configuration
GET/pitr/:projectId/statisticsGet PITR statistics
GET/pitr/:projectId/healthGet PITR health status
GET/pitr/:projectId/windowsList change windows
POST/pitr/restoreCreate PITR restore job
GET/pitr/:projectId/restore-jobsList restore jobs
GET/pitr/:projectId/restore-jobs/:jobIdGet restore job status
GET/pitr/:projectId/audit-log-statusCheck audit log configuration

Enable PITR

Enable Point-in-Time Recovery for a project.

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

{
"projectId": "proj_abc123",
"config": {
"retentionDays": 7,
"collections": ["users", "orders"],
"changeWindowMinutes": 1,
"storageDestinationId": "storage_xyz789"
}
}

Request Body:

FieldTypeRequiredDefaultDescription
projectIdstringYes-Project to enable PITR for
config.retentionDaysintegerNo7Days to retain PITR data
config.collectionsarrayNoAllCollections to monitor
config.changeWindowMinutesintegerNo1Change grouping interval
config.storageDestinationIdstringNoDefaultStorage for PITR data

Response:

{
"success": true,
"data": {
"id": "pitr_abc123",
"projectId": "proj_abc123",
"status": "initializing",
"config": {
"retentionDays": 7,
"collections": ["users", "orders"],
"changeWindowMinutes": 1
},
"enabledAt": "2024-01-15T10:00:00Z"
}
}

Disable PITR

Disable PITR for a project.

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

{
"deleteData": false
}

Request Body:

FieldTypeRequiredDefaultDescription
deleteDatabooleanNofalseDelete existing PITR data

Response:

{
"success": true,
"data": {
"projectId": "proj_abc123",
"status": "disabled",
"disabledAt": "2024-01-15T11:00:00Z",
"dataRetained": true
}
}

Pause PITR

Temporarily pause PITR change capture.

POST /api/v1/pitr/:projectId/pause
Authorization: Bearer YOUR_TOKEN
X-Organization-Id: YOUR_ORG_ID

Response:

{
"success": true,
"data": {
"projectId": "proj_abc123",
"status": "paused",
"pausedAt": "2024-01-15T11:00:00Z"
}
}
Gap in Protection

While paused, changes are NOT captured. You cannot restore to timestamps during the paused period.

Resume PITR

Resume PITR change capture after pausing.

POST /api/v1/pitr/:projectId/resume
Authorization: Bearer YOUR_TOKEN
X-Organization-Id: YOUR_ORG_ID

Response:

{
"success": true,
"data": {
"projectId": "proj_abc123",
"status": "active",
"resumedAt": "2024-01-15T12:00:00Z"
}
}

Get PITR Configuration

Retrieve current PITR configuration.

GET /api/v1/pitr/:projectId/config
Authorization: Bearer YOUR_TOKEN
X-Organization-Id: YOUR_ORG_ID

Response:

{
"success": true,
"data": {
"projectId": "proj_abc123",
"status": "active",
"config": {
"retentionDays": 7,
"collections": ["users", "orders"],
"changeWindowMinutes": 1,
"storageDestination": {
"id": "storage_xyz789",
"name": "Production S3",
"type": "s3"
}
},
"enabledAt": "2024-01-01T00:00:00Z",
"lastChangeAt": "2024-01-15T10:30:00Z"
}
}

Update PITR Configuration

Update PITR settings.

PATCH /api/v1/pitr/:projectId/config
Authorization: Bearer YOUR_TOKEN
X-Organization-Id: YOUR_ORG_ID
Content-Type: application/json

{
"retentionDays": 14,
"collections": ["users", "orders", "products"]
}

Request Body:

FieldTypeDescription
retentionDaysintegerDays to retain data
collectionsarrayCollections to monitor
changeWindowMinutesintegerChange grouping interval
storageDestinationIdstringStorage destination

Response:

{
"success": true,
"data": {
"projectId": "proj_abc123",
"config": {
"retentionDays": 14,
"collections": ["users", "orders", "products"],
"changeWindowMinutes": 1
},
"updatedAt": "2024-01-15T11:00:00Z"
}
}

Get PITR Statistics

Retrieve PITR statistics for a project.

GET /api/v1/pitr/:projectId/statistics
Authorization: Bearer YOUR_TOKEN
X-Organization-Id: YOUR_ORG_ID

Response:

{
"success": true,
"data": {
"projectId": "proj_abc123",
"totalChangesCaptured": 1250000,
"changeWindows": 10080,
"storageUsed": 524288000,
"oldestRecoveryPoint": "2024-01-08T10:00:00Z",
"latestRecoveryPoint": "2024-01-15T10:30:00Z",
"changesByCollection": {
"users": 450000,
"orders": 800000
},
"averageChangesPerHour": 7500,
"peakChangesPerHour": 25000
}
}

Get PITR Health

Check PITR health status.

GET /api/v1/pitr/:projectId/health
Authorization: Bearer YOUR_TOKEN
X-Organization-Id: YOUR_ORG_ID

Response:

{
"success": true,
"data": {
"projectId": "proj_abc123",
"status": "healthy",
"healthScore": 100,
"lastChangeCapture": "2024-01-15T10:30:00Z",
"captureLatency": 2,
"checks": {
"auditLogsEnabled": true,
"workerRunning": true,
"storageAccessible": true,
"withinRetention": true
},
"warnings": [],
"errors": []
}
}

Health Status Values

StatusDescription
healthyAll systems operational
degradedSome issues detected
unhealthyCritical issues
pausedPITR is paused
disabledPITR is disabled

List Change Windows

Get captured change windows.

GET /api/v1/pitr/:projectId/windows
Authorization: Bearer YOUR_TOKEN
X-Organization-Id: YOUR_ORG_ID

Query Parameters:

ParameterTypeDefaultDescription
pageinteger1Page number
limitinteger100Items per page
fromstring-Start timestamp
tostring-End timestamp
collectionstring-Filter by collection

Response:

{
"success": true,
"data": [
{
"id": "window_abc123",
"startTime": "2024-01-15T10:00:00Z",
"endTime": "2024-01-15T10:01:00Z",
"changesCount": 150,
"size": 52428,
"collections": ["users", "orders"],
"breakdown": {
"users": { "created": 10, "updated": 25, "deleted": 2 },
"orders": { "created": 50, "updated": 60, "deleted": 3 }
}
}
],
"meta": {
"page": 1,
"limit": 100,
"total": 10080,
"totalPages": 101
}
}

Create PITR Restore Job

Restore data to a specific point in time.

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

{
"projectId": "proj_abc123",
"targetTimestamp": "2024-01-15T10:30:00Z",
"options": {
"collections": ["users"],
"mergeMode": "overwrite",
"targetProjectId": "proj_def456",
"dryRun": false
}
}

Request Body:

FieldTypeRequiredDefaultDescription
projectIdstringYes-Source project
targetTimestampstringYes-ISO 8601 restore point
options.collectionsarrayNoAllCollections to restore
options.mergeModestringNooverwriteoverwrite, skip_existing, merge
options.targetProjectIdstringNoSameTarget project
options.dryRunbooleanNofalsePreview without writing

Response:

{
"success": true,
"data": {
"id": "pitr_restore_xyz789",
"projectId": "proj_abc123",
"targetTimestamp": "2024-01-15T10:30:00Z",
"status": "pending",
"options": {
"collections": ["users"],
"mergeMode": "overwrite",
"targetProjectId": "proj_def456"
},
"createdAt": "2024-01-15T11:00:00Z"
}
}

List Restore Jobs

Get all PITR restore jobs for a project.

GET /api/v1/pitr/:projectId/restore-jobs
Authorization: Bearer YOUR_TOKEN
X-Organization-Id: YOUR_ORG_ID

Response:

{
"success": true,
"data": [
{
"id": "pitr_restore_xyz789",
"targetTimestamp": "2024-01-15T10:30:00Z",
"status": "completed",
"documentsRestored": 15000,
"duration": 180,
"createdAt": "2024-01-15T11:00:00Z",
"completedAt": "2024-01-15T11:03:00Z"
}
],
"meta": {
"page": 1,
"limit": 20,
"total": 5
}
}

Get Restore Job Status

Get details of a specific restore job.

GET /api/v1/pitr/:projectId/restore-jobs/:jobId
Authorization: Bearer YOUR_TOKEN
X-Organization-Id: YOUR_ORG_ID

Response:

{
"success": true,
"data": {
"id": "pitr_restore_xyz789",
"projectId": "proj_abc123",
"targetTimestamp": "2024-01-15T10:30:00Z",
"status": "completed",
"progress": 100,
"options": {
"collections": ["users"],
"mergeMode": "overwrite",
"targetProjectId": "proj_def456"
},
"result": {
"documentsRestored": 15000,
"collectionsRestored": 1,
"baseBackupUsed": "bkp_abc123",
"changeWindowsApplied": 45
},
"timeline": [
{ "phase": "initializing", "timestamp": "2024-01-15T11:00:00Z" },
{ "phase": "downloading_base", "timestamp": "2024-01-15T11:00:05Z" },
{ "phase": "applying_changes", "timestamp": "2024-01-15T11:01:00Z" },
{ "phase": "verifying", "timestamp": "2024-01-15T11:02:50Z" },
{ "phase": "completed", "timestamp": "2024-01-15T11:03:00Z" }
],
"createdAt": "2024-01-15T11:00:00Z",
"completedAt": "2024-01-15T11:03:00Z"
}
}

Restore Status Values

StatusDescription
pendingJob queued
initializingPreparing restore
downloading_baseFetching base backup
applying_changesReplaying change windows
verifyingVerifying restored data
completedRestore successful
failedRestore failed

Check Audit Log Status

Verify that Firebase audit logs are properly configured.

GET /api/v1/pitr/:projectId/audit-log-status
Authorization: Bearer YOUR_TOKEN
X-Organization-Id: YOUR_ORG_ID

Response:

{
"success": true,
"data": {
"projectId": "proj_abc123",
"auditLogsEnabled": true,
"dataReadLogsEnabled": true,
"dataWriteLogsEnabled": true,
"lastLogReceived": "2024-01-15T10:30:00Z",
"logLag": 5,
"issues": []
}
}

Audit Log Not Configured

{
"success": true,
"data": {
"projectId": "proj_abc123",
"auditLogsEnabled": false,
"dataReadLogsEnabled": false,
"dataWriteLogsEnabled": false,
"lastLogReceived": null,
"issues": [
{
"code": "AUDIT_LOGS_DISABLED",
"message": "Firestore audit logs are not enabled",
"resolution": "Enable audit logs in Google Cloud Console > IAM & Admin > Audit Logs"
}
]
}
}

PITR Object

FieldTypeDescription
idstringPITR configuration ID
projectIdstringProject ID
statusstringCurrent status
configobjectConfiguration settings
enabledAtstringWhen PITR was enabled
lastChangeAtstringLast captured change
statisticsobjectUsage statistics

Error Responses

PITR Not Enabled

{
"success": false,
"error": {
"code": "PITR_NOT_ENABLED",
"message": "PITR is not enabled for this project"
}
}

Invalid Timestamp

{
"success": false,
"error": {
"code": "INVALID_TIMESTAMP",
"message": "Requested timestamp is outside the retention window",
"details": {
"requestedTimestamp": "2024-01-01T00:00:00Z",
"oldestAvailable": "2024-01-08T10:00:00Z",
"latestAvailable": "2024-01-15T10:30:00Z"
}
}
}

Audit Logs Required

{
"success": false,
"error": {
"code": "AUDIT_LOGS_REQUIRED",
"message": "Firebase audit logs must be enabled for PITR",
"details": {
"instructions": "Enable audit logs in Google Cloud Console"
}
}
}

Webhook Events

EventDescription
pitr.enabledPITR was enabled
pitr.disabledPITR was disabled
pitr.pausedPITR was paused
pitr.resumedPITR was resumed
pitr.restore.startedRestore job started
pitr.restore.completedRestore job completed
pitr.restore.failedRestore job failed
pitr.health.degradedHealth status degraded