A server that holds your only copy of a website is a server waiting to ruin your week. Disks fail, updates break things, and a bad command can wipe a directory in seconds. To back up a VPS to Google Drive automatically is to turn that risk into a routine: every night, a script copies your files and databases off the server and into storage somewhere else.
This guide walks through the whole setup with rclone and cron: what to back up, how to connect rclone, the backup script, scheduling, and the step most guides skip, proving the backup restores. A vps backup to google drive only counts when you have already restored from it once.
Decide what to back up before you touch rclone
A backup that copies everything is slow, expensive, and hard to restore. A backup that copies the right things is small and fast. For most servers, the right things are:
- Databases. MySQL, MariaDB, or PostgreSQL dumps hold your content, users, and settings, so dump them to files first, then back up the files.
- Website files. Your web root, usually
/var/www, plus any uploads directory. - Configuration. Nginx or Apache vhost files, PHP settings, and cron jobs. Without these, a restore means rebuilding the server from memory.
- Application data. Anything your apps store outside the web root, such as Docker volumes or uploaded files in custom paths.
Skip caches, logs, and the operating system itself. You can reinstall an OS in minutes, but you cannot recreate a database from a log file. If your server runs WordPress, the process for backing up WordPress to Google Drive from a VPS follows the same pattern, with a few WordPress-specific paths to know.
What you need before you start
You need SSH access to a VPS with root or sudo, a Google account with free Drive space, and about 30 minutes. Google Drive gives every account 15 GB free, shared across Gmail, Drive, and Photos, so check how much room you have before the first backup runs. A server with several gigabytes of uploads will need a paid Google One plan, so check official pricing before you commit to Drive as your only backup target.
Install rclone, a free command-line tool that copies files to cloud storage:
curl https://rclone.org/install.sh | sudo bash
rclone version
Connect rclone to Google Drive
Run rclone config and create a new remote. Choose Google Drive, name it gdrive, and leave the client ID and secret blank. When rclone asks for access, it opens a browser window for approval. On a headless VPS there is no browser, so use the headless option instead:
rclone config --headless
rclone prints a link. Open it on your own computer, sign in, approve access, and paste the code back into the terminal. Then test the remote:
rclone mkdir gdrive:vps-backups
rclone ls gdrive:vps-backups
If the folder lists without errors, the connection works. For unattended backups, a Google service account is cleaner than a personal OAuth token, because it never expires.
Back up a VPS to Google Drive with a backup script
A rclone google drive backup works best as two steps in one script: create the backup files locally first, then upload them. Dumping a database straight to Drive is slow and fragile; dumping it to disk first gives you a file you can check, compress, and upload in one move.
Create /usr/local/bin/vps-backup.sh:
#!/bin/bash
set -e
DATE=$(date +%Y-%m-%d)
BACKUP_DIR=/var/backups/daily
mkdir -p "$BACKUP_DIR"
# Database dumps
mysqldump --all-databases --single-transaction | gzip > "$BACKUP_DIR/db-$DATE.sql.gz"
# Website files and config
tar -czf "$BACKUP_DIR/www-$DATE.tar.gz" /var/www
tar -czf "$BACKUP_DIR/config-$DATE.tar.gz" /etc/nginx /etc/php
# Upload to Google Drive
rclone sync "$BACKUP_DIR" gdrive:vps-backups --delete-after --transfers 4
Make it executable with chmod +x /usr/local/bin/vps-backup.sh. The --single-transaction flag keeps InnoDB dumps consistent without locking tables, and --delete-after removes files from Drive that no longer exist locally. If you run PostgreSQL instead of MySQL, swap mysqldump for pg_dumpall. For a deeper look at the database half of this job, see the guide to backing up MySQL databases automatically with mysqldump and cron.
This script keeps the same files on disk that it uploads, so a server with 20 GB of data needs 20 GB of local room. If disk space is tight, upload each archive right after creating it and delete the local copy.
Schedule the backup with cron
An automatic vps backup needs a schedule that runs without you, and cron is the simplest tool for that. Open the root crontab:
sudo crontab -e
Add a line that runs the script every night at 2 AM, when traffic is lowest:
0 2 * * * /usr/local/bin/vps-backup.sh >> /var/log/vps-backup.log 2>&1
Log output to a file. A cron job that fails silently is worse than no backup at all, because you keep believing you are protected. Check the log the morning after the first run and confirm the new files appear in Drive. Then add a simple check that tells you when a backup stops happening, such as a second cron job that emails you if the newest file in Drive is older than 36 hours.
Prove the backup restores before you need it
Most backup guides end at the upload, and that is the wrong place to stop. A backup you have never restored is a guess, not a safety net. Test the restore on a second server, a local virtual machine, or a cheap temporary VPS:
rclone copy gdrive:vps-backups/db-2026-12-06.sql.gz /tmp/restore/
gunzip /tmp/restore/db-2026-12-06.sql.gz
mysql < /tmp/restore/db-2026-12-06.sql
tar -xzf /tmp/restore/www-2026-12-06.tar.gz -C /
Then check that the site loads and the data looks right: log in, open a few pages, and confirm recent content is there. If the restore fails, fix the script now, while the live server still works. Repeat the test every few months and after any big change, such as a new database or a moved uploads folder.
Retention, encryption, and storage limits
A nightly backup that never deletes anything will fill Drive. Seven daily backups plus four weekly ones covers most situations: you can recover from yesterday’s mistake and from a problem you only noticed three weeks later. Manage retention in the local backup directory with a cleanup line:
find /var/backups/daily -type f -mtime +7 -delete
Keep weekly copies in a separate directory the cleanup line does not touch, and keep a second copy somewhere other than Google Drive. One provider can have an outage or lock an account, and nightly backups to an external drive give you a local copy that works even when the internet does not.
Files on Google Drive are encrypted by Google, but Google holds the keys. If your backups contain customer data or passwords, encrypt the archives before upload. rclone has a built-in crypt remote that encrypts file names and contents on the way up, so Drive stores only unreadable data. Point the script at the crypt remote instead of the plain one.
How rclone compares with the alternatives
| Method | Best for | Downside |
|---|---|---|
| rclone to Google Drive | Small to medium servers, cheap off-site copy | Daily upload limits, no built-in deduplication |
| restic to cloud storage | Large servers, incremental backups, encryption built in | More setup, needs an S3-compatible target |
| Provider snapshots | Full-disk recovery in minutes | Stays with one provider, costs add up per GB |
| rsync to another VPS | Fast restores, full control | You manage the second server and its disks |
rclone wins on simplicity and cost for most small servers. restic wins when backups get large, because it only uploads changed blocks instead of whole archives; the guide to backing up a VPS to S3-compatible storage with restic walks through it. Provider snapshots are the fastest way back from a dead disk, but they live in the same account as the server, so they are not a real off-site backup on their own.
Mistakes that leave you with nothing
Four mistakes show up again and again. First, backing up to the same disk as the live data: a disk failure takes both copies. Second, never testing a restore. Third, backing up files but not the database, or the database but not the files. Fourth, letting the backup job fail quietly for weeks because nobody reads the log. Add an alert for a missing backup and the whole setup gets far more reliable.
Google Drive also has daily upload limits, and a very large first backup can hit them. If the first run stalls partway, split the upload into smaller pieces or let it finish over a couple of nights. After that, nightly changes are small and the upload stays quick.
Set the script up tonight, check the log tomorrow morning, and run a restore test this week. After that, the backup runs itself, and the next time a disk fails or an update goes wrong, recovery is a download and a restore instead of a rebuild from scratch.