Codely uses an automated system to back up and restore database snippet data securely. All backups are encrypted using AES-256-GCM.
To use the backup and recovery system, you must set the following environment variables in your .env or .env.local:
# Encryption key for AES-256-GCM (must be a secret)
BACKUP_ENCRYPTION_KEY="your-secure-encryption-key"
# Secret required to trigger the cron backup API
CRON_SECRET="your-cron-secret-token"
# API Key required to trigger admin recovery routes
ADMIN_API_KEY="your-admin-api-key"Backups are run automatically using Vercel Cron. The configuration is defined in vercel.json which triggers the /api/cron/backup endpoint every day at midnight (UTC).
You can manually trigger the cron job locally:
curl -H "Authorization: Bearer <CRON_SECRET>" http://localhost:3000/api/cron/backupYou can run a backup manually from the command line:
npx tsx scripts/backup.tsThis will fetch all snippets, encrypt them, and store them in the backups/ directory as snippets-backup-<timestamp>.enc.
You can list all available backups:
npx tsx scripts/restore.ts listTo perform a Full Restore of all snippets from a specific backup file:
npx tsx scripts/restore.ts snippets-backup-1234.encTo perform a Partial Restore (only restoring specific snippets by their IDs):
npx tsx scripts/restore.ts snippets-backup-1234.enc "snippet-id-1,snippet-id-2"You can also trigger a recovery via the API endpoint:
curl -X POST http://localhost:3000/api/admin/recovery \
-H "Authorization: Bearer <ADMIN_API_KEY>" \
-H "Content-Type: application/json" \
-d '{"filename":"snippets-backup-1234.enc", "snippetIds":["snippet-id-1"]}'Currently, backups are stored in the local file system backups/ directory. For production environments where the local file system is ephemeral, lib/backup.service.ts should be updated to upload these encrypted files to an S3 bucket or equivalent cloud storage provider.