Recently, a client asked us for a way to back up their PostgreSQL databases. While the "standard" advice is often to pay for expensive managed cloud storage, we looked at their actual requirements and realized they didn't need a high-priced enterprise solution.
To help them minimize costs, we recommended a custom setup instead of a paid service. We delivered a simple, reliable, and—most importantly—completely free system using Docker, Google Drive, and a handy tool called rclone.
The Goal
The client needed their databases backed up every day, compressed to save space, and stored safely off-site. Because their storage requirements were quite small, paying for an expensive enterprise cloud solution would have been a waste of money.
Instead, we suggested a smarter route: use their existing 15GB of free Google Drive storage as the "vault." It’s secure, reliable, and perfectly sized for their needs.
Step 1: The "Box" (Docker)
We put everything into a Docker container. Think of this as a pre-packaged box that has all the tools needed to talk to the database and Google Drive.
To make it bulletproof on their Windows server, we baked the settings directly into the image to avoid common path errors. For example, here is how a typical Dockerfile for this setup looks:
# Example Dockerfile
FROM alpine:3.18
RUN apk add --no-cache postgresql-client rclone bash ca-certificates
RUN mkdir -p /backups /config
COPY ./config /config
COPY ./scripts/backup-db.sh /scripts/backup-db.sh
RUN chmod +x /scripts/backup-db.sh
CMD ["/bin/bash", "-c", "while true; do /scripts/backup-db.sh; sleep 86400; done"]
Step 2: The "Courier" (Rclone)
To get the files from the server to Google Drive, we used rclone.
The Challenge: We first tried a "Service Account," but Google gives those zero storage space.
The Fix: We switched to a personal OAuth token. This let the system "log in" as the client and use their free 15GB quota.
Important Security Tip for Windows Users:
If you're trying to generate your token and Windows blocks the connection, you may need to temporarily stop the service that "hogs" the network ports. Always remember to turn it back on immediately after to keep your system working correctly.
- Stop the service:
net stop winnat
Start the service back up:
net start winnat
Step 3: Making it Permanent (The "Forever" Fix)
By default, Google tokens expire every 7 days if your Cloud Project is in "Testing" mode. To make sure the backup pipeline never stops, you need to "Publish" your app in the Google Cloud Console.
Simply click "Publish App" on the OAuth consent screen. This ensures your refresh token lasts indefinitely, so the client’s backups keep running month after month without anyone having to log in again.
Step 4: The "Brain" (The Script)
We wrote a simple script that automates the nightly tasks. For example, the core logic of the backup process looks like this:
# Example logic for the backup script:
# 1. Export the data
pg_dump -h db_host -U user -d database --file=backup.dump
# 2. Compress to save space
tar -czf backup.tar.gz backup.dump
# 3. Move to the cloud
rclone --config /config/rclone.conf copy backup.tar.gz gdrive:nordible/db-backups
The "Bonus" Feature: Auto-Cleanup
We didn't just want to upload files; we wanted the system to be truly "set-and-forget." As a bonus for the client, we added a cleanup rule: the script automatically deletes backups older than 5 days from both the server and Google Drive. This ensures they never run out of space and never have to delete files manually.
The Result: A Happy Client
By combining these free tools, we achieved a "set-and-forget" backup system.
Cost: $0/month.
Maintenance: None.
Peace of Mind: Priceless.
Now, every morning, our client can look at their Google Drive and see a fresh backup waiting for them. Simple, effective, and completely free.



SOCIAL SHARE CARD GENERATOR