Created
January 25, 2023 06:26
-
-
Save circuitsacul/e31da640eda7b573f9075dd7f6e8ffd5 to your computer and use it in GitHub Desktop.
automatic backups for postgresql databases using google/zx
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
#!/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