Create regular Postgres database backups on your local machine and get pinged on Discord when they run!
- Dumps your remote Postgres database into a
backupsdirectory on your local machine. - Sends you notifications in a Discord channel through a webhook.
- Automatically deletes old backups after a certain number of days to clear space on your local disk.
- Node.js v18 or higher.
- Recommended: PM2 to run the process.
Note: This does require your local machine being turned on, the process to be running and a stable internet connection to work. If the backup fails at the pre-defined backup time, it won't run again until the following day.
git clone https://github.com/pixxies/Postgres-Local-Backup.git
npm install
Change the values in sample.env to your details and rename the file to .env.
PG_HOST="" # my.host.tld
PG_PORT="5432" # Postgres default is 5432
PG_USER="" # admin
PG_PASSWORD="" # password123
PG_DATABASE="" # my_database
DISCORD_WEBHOOK="" # https://discord.com/api/webhooks/...
DISCORD_USERNAME="" # My Cool Bot
DISCORD_PING_ID="" # A Discord user ID like 643945264868098049 or role ID prefixed with a "&" symbol
DAYS_TO_KEEP="7" # Set to "0" to never expire - this may fill your disk space quicklyYou'll need to create a Discord webhook in a channel and paste the link into the .env file above.
The DISCORD_PING_ID is the Discord ID of the person the webhook will ping for notifications. You can make the webhook ping a role instead by prefixing a role ID with &, for example &761916863847333928.
Set the number of days to keep old dumps with the DAYS_TO_KEEP value in your .env file. To never delete old backups, set this value to 0.
- Open a new terminal window in your project directory.
- Run
npm run build && pm2 start npm --name "postgres-local-backups" -- start. - You'll recieve confirmation of startup and all events in the logs. Run
pm2 logs postgres-local-backupsto see the logs.