Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
363 changes: 363 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 23 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,31 @@ if (limit <= 0) {
process.exit(1);
}

// Validate required environment variables
const accountId = process.env.CLOUDFLARE_D1_ACCOUNT_ID;
const databaseId = process.env.CLOUDFLARE_D1_DATABASE_ID;
const apiKey = process.env.CLOUDFLARE_D1_API_KEY;

if (!accountId) {
console.error("Error: CLOUDFLARE_D1_ACCOUNT_ID environment variable is required.");
process.exit(1);
}
if (!databaseId) {
console.error("Error: CLOUDFLARE_D1_DATABASE_ID environment variable is required.");
process.exit(1);
}
if (!apiKey) {
console.error("Error: CLOUDFLARE_D1_API_KEY environment variable is required.");
process.exit(1);
}

const backup = await createBackup({
accountId: process.env.CLOUDFLARE_D1_ACCOUNT_ID!,
databaseId: process.env.CLOUDFLARE_D1_DATABASE_ID!,
apiKey: process.env.CLOUDFLARE_D1_API_KEY!,
accountId,
databaseId,
apiKey,
limit,
onProgress: (message) => console.log(message),
});

console.log(`\nBackup written to: ${path}`);
fs.writeFileSync(path, backup);
Loading