Postgres Backup to your Google Drive
Backup a Postgres DB to your Personal Google Drive
backup-postgres-gdrive
doiska/postgres-gdrive-backup
Just deployed
Supported Modes
-
Single shot: run once when the app starts or when the
Run Now
button is clicked.- Set the
CRON_EXPRESSION
to-1
and theRUN_ON_START
totrue
.
- Set the
-
Scheduled: run on a schedule.
- Set the
CRON_EXPRESSION
to a valid cron expression.
- Set the
How to setup
Google Cloud Platform Setup
- Log-in to the Google Cloud Console.
- Enable Google Drive API.
- Then create a new service account
- Click in the three dots on the right of the service account you just created and click on Manage keys.
- Create a new json key and download the file.
- Now go to your Google Drive and create a new folder where the backups will be stored.
- Save the Folder ID, it's the string after
https://drive.google.com/drive/folders/{ID HERE}
.
- Save the Folder ID, it's the string after
- Share the folder with the service account email (client_email), you can find it on the JSON file you downloaded on the previous step.
- The email looks like:
[email protected]
- Make sure to include Editor permissions.
- The email looks like:
Environment Setup
You can use .env.default
as a template for your environment variables.
SERVICE_ACCOUNT
: The downloaded JSON string of the service account.
{"type":"service_account","project_id":"projectname","private_key_id":"123"}
FOLDER_ID
: The ID of the folder where the backups will be stored.
- You can find the ID on the URL of the folder, it's the string after
https://drive.google.com/drive/folders/
. - Example:
https://drive.google.com/drive/folders/1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7
- Your ID:
1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7
DATABASE_URL
: The connection string of your Postgres database.
CRON_EXPRESSION
: A schedule for the backups.
- Example:
0 0 * * *
(every day at midnight) - You can use crontab.guru to help you create the expression.
- If set to
-1
the backup will run without a schedule, only once when the app starts.
FILE_PREFIX
: A prefix for the backup files.
- Example:
my-database-backup-
- Result:
my-database-backup-2024-02-01.sql.tar.gz
RUN_ON_START
: If set to true
, the backup will run once when the app starts.
Template Content
backup-postgres-gdrive
doiska/postgres-gdrive-backupFOLDER_ID
The folder id from your GDrive, it will be at the end of the url.
DATABASE_URL
Your database url (includes postgresql://))
SERVICE_ACCOUNT
Your Service Account json (https://console.cloud.google.com/projectselector2/iam-admin/serviceaccounts)