Backup your Website from a Web Server to Google Drive
We will use Google Drive to backup our files from a server automatically every month at no additional cost.
Updated 3 July 2026: this method still works. I've tightened up a couple of things that aged: the service account doesn't need the "Owner" role, and newer Ubuntu blocks system-wide pip installs, so there's a note on that below.
A lot of VPS providers don't include backups, and the ones that do usually charge extra for it. You can sidestep that with Google Drive, which already gives you 15 GB free, plenty for a few small sites.
We'll use Python and the Google Drive API to push the backups up, then a cron job to run it on a schedule and forget about it.
Getting the Google Drive API
To get the token for permanent, hands-off authentication, we'll use a Google Cloud project. Head to Google Cloud and create a "New Project".

Open "IAM & Admin" and click "Service Accounts".

Click "Create Service Account", give it any name and ID you like, and click "Create".

The next step asks for a project role. The original version of this guide picked "Owner", but you don't actually need it. This service account gets its Drive access purely from the folder you'll share with it in a minute, not from any project role, so you can leave it empty and click "Continue". Granting Owner just hands out more access than the job needs.

Now open the service account, go to "Keys", click "Add Key", and choose "JSON". A key file downloads to your computer. Keep it safe, because you can't download it again.

Note down the service account's email address, we'll need it shortly.
gdrive@signal-signal-111111.iam.gserviceaccount.com
In your personal Google Drive, create a new folder and share it with that email.

Give it Editor access and click "Done". This is the folder your backups will land in, and because it lives in your own Drive, the files count against your 15 GB, not the service account.

That's the Google Drive side sorted. Keep the key file, the email, and the folder link handy for the next section.
Setting up the server
Install the Python packages the script needs:
sudo apt install python3-pip
pip3 install google-api-python-client requests pathlib httplib2==0.15.0On Ubuntu 23.04 and newer, that pip command will refuse to run with an "externally-managed-environment" error. That's expected now: modern Debian and Ubuntu don't want you installing packages system-wide. The clean fix is a virtual environment:
sudo apt install python3-venv
python3 -m venv ~/gdrive-env
source ~/gdrive-env/bin/activate
pip install google-api-python-client requests pathlib httplib2==0.15.0If you'd rather not bother with a venv, appending --break-system-packages to the pip3 command also works, though a venv is the tidier option.
What the script does:
1. Backs up the directory you choose to Google Drive.
2. Deletes old backups from your web server.
Download the script from my GitHub repository and drop in the email and the folder ID from the folder link you noted earlier.
Save the script and copy the key file over to your server. Time to run it. You pass the action, the key location, and the directory you want backed up:
sudo python3 gdrive.py backup [token location] [directory location]
So to back up the "www" folder:
sudo python3 gdrive.py backup /var/token.json /var/www/That's it. You'll watch it archive the folder and upload it, with the current date and time baked into the filename. The other command is "clean", which clears out old backups from the Drive folder:
sudo python3 gdrive.py clean /var/token.jsonNow let's automate it. I'll run the backup on the 1st of every month with a small shell script and a cron job. Create "backup.sh" on your server:
#! /bin/bash
cd /var/backup #Location of your python script.
/usr/bin/python3 gdrive.py backup /var/token.json /var/www/Make it executable:
chmod +x backup.shOpen the crontab:
crontab -eAdd this line, assuming "backup.sh" sits in "/var":
0 0 1 * * /var/backup.shSave and exit. It'll now back up your files on its own, first of every month.
If you'd prefer something even simpler and don't need the Python route, rclone can sync a folder to Google Drive in a single command and is worth a look. But the script above is still what I run, and it's held up fine.