Skip to content

Instantly share code, notes, and snippets.

@CircuitSacul
Created January 25, 2023 06:26
Show Gist options
  • Save CircuitSacul/e31da640eda7b573f9075dd7f6e8ffd5 to your computer and use it in GitHub Desktop.
Save CircuitSacul/e31da640eda7b573f9075dd7f6e8ffd5 to your computer and use it in GitHub Desktop.
automatic backups for postgresql databases using google/zx
#!/usr/bin/env zx
await cd('BACKUP FOLDER')
let files = await $`ls`
let min = 0
files.stdout.split("\n").forEach(file => {
let fileNumber = Number.parseInt(file.split(".")[0], 10)
if (fileNumber > min) {
min = fileNumber
}
})
let fileNameNumber = String(min+1).padStart(4, "0")
await $`pg_dump -d DATABASE -h localhost -U USERNAME -Z 9 -f ${fileNameNumber}.sql.gz`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment