If your WordPress site lives on a VPS, you are the backup plan. There is no hosting panel quietly saving copies for you, and a failed disk, a bad plugin update, or a hacked admin account can take the whole site down in minutes. Learning how to back up WordPress to Google Drive automatically from your VPS fixes that gap with tools you already have: a small shell script, rclone, and cron. Once it runs, a fresh copy of your database and files lands in your Drive every night without you touching anything.
This guide walks through the full setup on Ubuntu 24.04 with Nginx and PHP-FPM, the stack most self-hosted WordPress sites use. The same steps work on Debian with only small path changes. You need SSH access, a Google account with free Drive space, and about 30 minutes. A wordpress google drive backup built this way costs nothing beyond the storage you already have, and you control every part of it.
What You Need Before You Start
Before you install anything, gather the details the backup script will need. Open your wp-config.php and note the database name, user, and password. Also note the path to your WordPress files, usually /var/www/your-site.com, and check the site size with du -sh /var/www/your-site.com. A site with a few hundred megabytes of uploads fits easily in the free 15 GB Google gives every account; a site with years of uncompressed photos may need a paid plan, so check official pricing first.
Decide what counts as a complete backup. For WordPress, that means two things: a database dump and a copy of the files, mainly wp-content plus wp-config.php. Core WordPress files can be downloaded again any time, so skipping them keeps each backup small and fast. If you want a deeper look at what a daily routine should cover, read our guide on setting up daily database backups for WordPress with a simple script, which covers the mysqldump side in more detail.
Storing the backup on the same VPS defeats the purpose: if the disk dies, the backup dies with it. Google Drive is the off-site copy here, which matches the 3-2-1 backup rule for servers: three copies, two media, one off site.
Set Up rclone with Google Drive
rclone is a command-line tool that copies files to cloud storage. Install it from the official script rather than the older package in the Ubuntu repository, so you get a current version with working Drive support:
curl https://rclone.org/install.sh | sudo bash
rclone version
Next, connect rclone to your Google Drive. Run rclone config, choose to create a new remote, name it gdrive, and pick Google Drive from the list of storage types. Leave the client ID and secret blank to use rclone’s defaults, choose the default full-access scope, and leave the root folder ID empty so rclone starts at the top of your Drive.
The tricky part is authentication. rclone will ask whether to use auto config. On a headless VPS, answer no, then run the command it prints on your own computer, where a browser is available. Sign in with the Google account you want to use for backups, approve access, and paste the code back into the VPS terminal. A dedicated Google account just for backups is a good idea: it keeps site backups separate from your personal files.
Test the connection with a small upload before you trust it:
echo "rclone test" > /tmp/rclone-test.txt
rclone copy /tmp/rclone-test.txt gdrive:/wordpress-backups/
rclone ls gdrive:/wordpress-backups/
If the file shows up in the listing, the link works. Delete the test file from Drive afterwards. This rclone wordpress backup connection is the foundation for everything that follows, so do not skip the test.
Back Up WordPress to Google Drive: The Backup Script
Now write the script that does the real work. It dumps the database, archives the files, uploads both to Drive, and cleans up after itself. Create it at /usr/local/bin/wp-backup.sh:
#!/bin/bash
set -e
SITE="your-site.com"
DB_NAME="your_db"
DB_USER="your_db_user"
DB_PASS="your_db_password"
WP_PATH="/var/www/your-site.com"
BACKUP_DIR="/var/backups/wordpress"
DATE=$(date +%Y-%m-%d)
mkdir -p "$BACKUP_DIR"
mysqldump -u "$DB_USER" -p"$DB_PASS" "$DB_NAME" | gzip > "$BACKUP_DIR/$SITE-db-$DATE.sql.gz"
tar -czf "$BACKUP_DIR/$SITE-files-$DATE.tar.gz" -C /var/www "$SITE/wp-content" "$SITE/wp-config.php"
rclone copy "$BACKUP_DIR/$SITE-db-$DATE.sql.gz" gdrive:/wordpress-backups/$SITE/
rclone copy "$BACKUP_DIR/$SITE-files-$DATE.tar.gz" gdrive:/wordpress-backups/$SITE/
rm -f "$BACKUP_DIR/$SITE-db-$DATE.sql.gz" "$BACKUP_DIR/$SITE-files-$DATE.tar.gz"
Replace the placeholder values with your real database credentials and paths, then make the script executable with chmod +x /usr/local/bin/wp-backup.sh. The tar command only includes wp-content and wp-config.php, which keeps the archive small, and the script deletes the local copies after upload so a small VPS disk never fills up with old archives.
Lock the script down with chmod 700 /usr/local/bin/wp-backup.sh so only root can read the database password inside it. Run it once by hand before you schedule it, then check Drive to confirm both files arrived and their sizes look right.
Schedule It with Cron
A backup script that only runs when you remember to run it is not a backup system. A wordpress backup cron job fixes that by running the script on a schedule. Open root’s crontab with sudo crontab -e and add a line that runs the script at 2 a.m., when traffic is usually low:
0 2 * * * /usr/local/bin/wp-backup.sh >> /var/log/wp-backup.log 2>&1
The log file matters. Without it, a failed backup fails silently and you only find out when you need the backup. Check the log the morning after the first scheduled run. If you see rclone errors about an expired token, run rclone config reconnect gdrive: to refresh the connection.
An automatic wordpress backup vps setup like this one should also warn you when it fails. Add a second cron line that checks the log for errors and mails you, or point your uptime monitor at a status file the script writes on success.
Test the Restore Before You Need It
A backup you have never restored is a guess, not a safety net. Once a week for the first month, download the latest backup from Drive to a test location and restore it somewhere safe, never on top of the live site. A staging copy on the same VPS works fine for this. The steps are short: create an empty database, import the dump, extract the files archive, and point a test Nginx server block at the copy. If the test site loads and you can log in to /wp-admin/, the backup is real.
This test catches the mistakes that a successful upload hides. A dump taken with the wrong database name restores to an empty site. A tar archive that missed wp-config.php leaves the test site asking for install details. A Drive upload that stopped halfway leaves a truncated archive that tar refuses to open. Finding any of these during a calm test beats finding them during an outage. Our guide on how to test your VPS backup by restoring it before you actually need it walks through a full restore drill step by step.
Retention, Security, and What Can Go Wrong
Daily backups pile up fast. A 500 MB site backed up daily uses 15 GB in a month, which eats a free Drive account in weeks. Add a retention rule to the script or a separate cleanup job: keep seven daily backups and four weekly ones, and delete the rest with rclone delete --min-age 30d gdrive:/wordpress-backups/your-site.com/.
Security deserves the same attention as scheduling. The rclone token on your VPS can read and write your Drive, so keep SSH key-only, keep the system updated, and do not reuse the backup Google account for anything else. If you want a second off-site copy in different storage, the same script pattern works with other destinations, and our guide to storing VPS backups off site so one server failure does not wipe you out covers the options beyond Drive.
A few problems come up often. Large media libraries make the tar step slow, so exclude the cache folders inside wp-content and any backup-plugin folders holding old archives. A backup that runs during a big import can produce a database dump mid-write, so schedule it away from bulk work. And if rclone uploads stall, check the VPS disk first: a full disk breaks the dump before the upload even starts.
Set it up once, test the restore, and let cron do the rest. Your future self, staring at a dead disk at midnight, will be glad the copies are already sitting in Drive.