Created
December 15, 2023 17:44
-
-
Save lumpenspace/2c593eabfa3969c2ad84f167500532f1 to your computer and use it in GitHub Desktop.
sqlite backup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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