Endpoint
Creates a complete backup of your Blnk database and stores it on the server’s local disk. This is useful for local backups and disaster recovery.
Response
Success message indicating the backup was created successfully
Example Request
curl -X GET "https://api.blnk.io/backup" \
-H "Authorization: Bearer YOUR_API_KEY"
Example Response
Backup Details
What’s Included
The backup includes:
- All ledgers
- All balances
- All transactions
- All identities
- All accounts
- All reconciliation data
- All webhook configurations
- All API keys (encrypted)
- All metadata
Storage Location
Backups are stored on the server’s local disk in the configured backup directory. The exact location depends on your Blnk configuration.
The backup is created as a PostgreSQL dump file in a compressed format, typically:
- Format: Custom PostgreSQL dump format
- Compression: Enabled by default
- Filename: Typically includes timestamp (e.g.,
blnk_backup_20240304_120000.dump)
Error Responses
Error object with details about what went wrong
Common Errors
- 400 Bad Request: Backup configuration error
- 500 Internal Server Error: Failed to create backup
Use Cases
Scheduled Backups
Create automated backup schedules:
const createScheduledBackup = async () => {
console.log('Starting scheduled backup...');
try {
const response = await fetch('https://api.blnk.io/backup', {
headers: {
'Authorization': 'Bearer YOUR_API_KEY'
}
});
if (response.ok) {
const result = await response.json();
console.log('✓ Backup completed:', result);
// Log to monitoring system
await logBackupSuccess({
timestamp: new Date().toISOString(),
type: 'disk',
status: 'success'
});
} else {
throw new Error('Backup failed');
}
} catch (error) {
console.error('✗ Backup failed:', error);
// Alert operations team
await alertBackupFailure(error);
}
};
// Schedule daily backups at 2 AM
const scheduleBackups = () => {
const cron = require('node-cron');
// Run every day at 2:00 AM
cron.schedule('0 2 * * *', createScheduledBackup);
console.log('Backup schedule configured');
};
Pre-Migration Backup
Create a backup before major changes:
const preMigrationBackup = async () => {
console.log('Creating pre-migration backup...');
const response = await fetch('https://api.blnk.io/backup', {
headers: {
'Authorization': 'Bearer YOUR_API_KEY'
}
});
if (response.ok) {
console.log('✓ Pre-migration backup complete');
console.log('Safe to proceed with migration');
return true;
} else {
console.error('✗ Backup failed - aborting migration');
return false;
}
};
// Use before migrations
const runMigration = async () => {
const backupSuccess = await preMigrationBackup();
if (backupSuccess) {
await performMigration();
} else {
console.log('Migration cancelled due to backup failure');
}
};
Development Environment Backup
Create backups before testing:
const devBackup = async (testName) => {
console.log(`Creating backup before test: ${testName}`);
const response = await fetch('https://api.blnk.io/backup', {
headers: {
'Authorization': 'Bearer YOUR_API_KEY'
}
});
if (response.ok) {
console.log('✓ Backup created');
return true;
}
return false;
};
Best Practices
1. Regular Backup Schedule
Establish a consistent backup schedule:
// Daily backups
cron.schedule('0 2 * * *', () => createBackup());
// Weekly backups (Sunday at 1 AM)
cron.schedule('0 1 * * 0', () => createBackup());
// Monthly backups (1st of month at 3 AM)
cron.schedule('0 3 1 * *', () => createBackup());
2. Verify Backup Success
Always verify that backups completed:
const verifiedBackup = async () => {
const response = await fetch('https://api.blnk.io/backup', {
headers: { 'Authorization': 'Bearer YOUR_API_KEY' }
});
if (response.ok) {
// Verify file exists and has reasonable size
const backupInfo = await checkBackupFile();
if (backupInfo.size > 0) {
console.log('✓ Backup verified');
return true;
}
}
return false;
};
3. Monitor Disk Space
Ensure adequate disk space for backups:
const checkDiskSpace = async () => {
const { disk } = require('check-disk-space');
const space = await disk('/');
const minRequired = 10 * 1024 * 1024 * 1024; // 10 GB
if (space.free < minRequired) {
console.warn('Low disk space! Free:', space.free);
await alertOps('Low disk space for backups');
return false;
}
return true;
};
const safeBackup = async () => {
const hasSpace = await checkDiskSpace();
if (hasSpace) {
await createBackup();
} else {
console.error('Insufficient disk space for backup');
}
};
4. Implement Backup Rotation
Keep a limited number of backups:
const rotateBackups = async (maxBackups = 7) => {
const fs = require('fs').promises;
const path = require('path');
const backupDir = '/path/to/backups';
const files = await fs.readdir(backupDir);
// Sort by creation time (oldest first)
const backupFiles = files
.filter(f => f.endsWith('.dump'))
.map(f => ({
name: f,
path: path.join(backupDir, f),
time: fs.stat(path.join(backupDir, f)).then(s => s.mtime)
}));
// Delete oldest backups if we have too many
if (backupFiles.length > maxBackups) {
const toDelete = backupFiles.slice(0, backupFiles.length - maxBackups);
for (const file of toDelete) {
await fs.unlink(file.path);
console.log(`Deleted old backup: ${file.name}`);
}
}
};
Backup vs S3 Backup
| Feature | Disk Backup | S3 Backup |
|---|
| Storage Location | Local server disk | Amazon S3 |
| Accessibility | Server only | Anywhere |
| Durability | Single copy | Multiple copies |
| Cost | Disk space | S3 storage fees |
| Speed | Fast | Depends on network |
| Best For | Quick recovery | Long-term storage |
When to Use Disk Backups
- Quick local recovery: Fast restore times for local failures
- Development/testing: Easy backup and restore during development
- Pre-deployment: Backup before deploying changes
- Compliance: Local backup requirements
- Cost-sensitive: When cloud storage costs are a concern
Recovery
To restore from a disk backup:
# Restore using pg_restore
pg_restore -d blnk_database /path/to/backup.dump
Consult your database administrator for the exact restore procedure.
Monitoring and Alerts
const monitorBackups = async () => {
const lastBackup = await getLastBackupTime();
const hoursSinceBackup = (Date.now() - lastBackup) / (1000 * 60 * 60);
if (hoursSinceBackup > 24) {
await sendAlert({
severity: 'warning',
message: `No backup in ${hoursSinceBackup.toFixed(1)} hours`
});
}
};
// Check every hour
setInterval(monitorBackups, 60 * 60 * 1000);