πŸ”’ How I Back Up My Web App to Google Drive with rclone
Adam C. |

To protect against server failure, data loss, or accidental changes, I’ve automated daily backups of my web app β€” including both the MongoDB database and NodeBB forum files β€” and synced them securely to Google Drive using rclone.

Photo by Siyuan Hu on Unsplash

🧰 Tools Used

MongoDB for database

NodeBB for forum data

mongodump for database backup

rclone to sync backups to Google Drive

cron to automate the task

πŸ“ Backup Script

Here’s the backup script I run every night at 2 AM:

#!/bin/bash
source /home/adam/.mongodump.cnf  # contains MONGODB_URI or credentials

BACKUP_DIR="/home/adam/backups"
TIMESTAMP=$(date +"%F-%H%M")
MONGO_BACKUP="$BACKUP_DIR/mongo/mongo-backup-$TIMESTAMP"
FILES_BACKUP="$BACKUP_DIR/nodebb-files/files-backup-$TIMESTAMP"

mkdir -p "$MONGO_BACKUP" "$FILES_BACKUP"

# Backup MongoDB
mongodump --out "$MONGO_BACKUP"

# Backup NodeBB uploads/configs/logs (customize as needed)
cp -r /home/adam/nodebb/public/uploads "$FILES_BACKUP/uploads"
cp -r /home/adam/nodebb/config.json "$FILES_BACKUP/config.json"
cp -r /home/adam/nodebb/logs "$FILES_BACKUP/logs"

# Clean up local backups older than 7 days
find "$BACKUP_DIR/mongo" -type d -mtime +7 -exec rm -rf {} \;
find "$BACKUP_DIR/nodebb-files" -type d -mtime +7 -exec rm -rf {} \;

# Sync to Google Drive
rclone sync "$BACKUP_DIR" gdrive:NodeBBBackups --delete-during

πŸ” Set Up Cron Job

To run the backup daily at 2:00 AM:

crontab -e

Add this line:

0 2 * * * /home/adam/cron/backup.sh >> /home/adam/cron/backup.log 2>&1

☁️ Google Drive Setup with rclone

If you're starting from scratch:

Install rclone:

curl https://rclone.org/install.sh | sudo bash

Configure a Google Drive remote:

rclone config

Choose n for new remote

Name: gdrive

Storage: drive

Add your own client ID and secret from Google Cloud (optional but recommended)

Use rclone authorize if configuring from a headless server

Test with:

rclone lsd gdrive:

πŸ” Tip: Keep Only the Latest Cloud Backup

To avoid using excess space on Google Drive, the sync command:

rclone sync "$BACKUP_DIR" gdrive:NodeBBBackups --delete-during

ensures the remote backup mirrors your local backup folder β€” deleting outdated files automatically.

βœ… Automate It (Optional)

You can create a cron job:

0 2 * * * /usr/bin/rclone sync /home/adam/backups gdrive:NodeBBBackups --delete-during >> /var/log/rclone.log 2>&1

This syncs your backups daily at 2:00 AM.