Skip to content

Instantly share code, notes, and snippets.

@lumpenspace
Created December 15, 2023 17:44
Show Gist options
  • Save lumpenspace/2c593eabfa3969c2ad84f167500532f1 to your computer and use it in GitHub Desktop.
Save lumpenspace/2c593eabfa3969c2ad84f167500532f1 to your computer and use it in GitHub Desktop.
sqlite backup
import * as cron from 'node-cron';
import * as shell from 'shelljs';
cron.schedule('59 23 * * *', function() {
const dateString = new Date().toISOString().slice(0, 10);
const bukcet = 'test-bucket';
const filename = `${dateString}-dump.sql`;
commands = [
`sqlite3 database.sqlite .dump > ${filename}`,
`wrangler r2 object put ${bucket}/${filename} --file={filename} --content-type="application/sql"`,
]
commands.forEach(command => {
const result = shell.exec(command);
if (result.code !== 0) {
console.error(result.stderr);
shell.exit(1);
}
})
console.log(`Backup complete: ${bucket}/${filename}`);
shell.exit(0);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment