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.
MongoDB for database
NodeBB for forum data
mongodump for database backup
rclone to sync backups to Google Drive
cron to automate the task
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-duringTo run the backup daily at 2:00 AM:
crontab -eAdd this line:
0 2 * * * /home/adam/cron/backup.sh >> /home/adam/cron/backup.log 2>&1rcloneIf you're starting from scratch:
Install rclone:
curl https://rclone.org/install.sh | sudo bashConfigure a Google Drive remote:
rclone configChoose 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:To avoid using excess space on Google Drive, the sync command:
rclone sync "$BACKUP_DIR" gdrive:NodeBBBackups --delete-duringensures the remote backup mirrors your local backup folder β deleting outdated files automatically.
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.