Configuring automatic backups of your website means never having to worry about losing your website’s data in the case of an emergency.
In this tutorial you will learn how to configure automatic daily backups of your website on Google Cloud by configuring an automatic-backup script.
The automatic backup script creates a new backup (snapshot) of your website based on predefined specifications which you’ll define in this tutorial.
Before stating this tutorial, it is essential that you reserve a static IP address for your VM instance. If you don’t reserve a static IP address before starting this tutorial, Google Cloud will automatically assign a new IP Address to your VM instance when it restarts.
If you haven’t yet launched a website on Google Cloud, check out the following beginner tutorials for instructions on how to install WordPress on Google Cloud:
- How to Install WordPress on Google Cloud for Beginners
- How to Configure a Domain Name for WordPress on Google Cloud
There are 5 steps in this tutorial:
1. Enable Compute Engine access
2. Clone automatic backup script
chmod +x gcloud-snapshot.sh
sudo mkdir -p /opt/google-compute-snapshot
sudo mv gcloud-snapshot.sh /opt/google-compute-snapshot/
3. Create cronjob to automate script
sudo crontab -e
10 18 * * * /opt/google-compute-snapshot/gcloud-snapshot.sh >> /var/log/cron/snapshot.log 2>&1
4. Enable logging for cronjob
sudo mkdir /var/log/cron
sudo touch /var/log/cron/snapshot.log
sudo chgrp adm /var/log/cron/snapshot.log
sudo chmod 664 /var/log/cron/snapshot.log
sudo nano /etc/logrotate.d/cron
create 664 root adm
5. Optional configurations
Defining the total number of backups to save
In this tutorial, you configured the system to save a total of 7 backups. You can change the total number of backups to whatever you want, simply by incorporating the -d flag.
10 18 * * * /opt/google-compute-snapshot/gcloud-snapshot.sh -d 30 >> /var/log/cron/snapshot.log 2>&1
Testing the automatic backup script
You can test whether the automatic backup script is working by executing the backup script in your SSH terminal.
/opt/google-compute-snapshot/gcloud-snapshot.sh >> /var/log/cron/snapshot.log 2>&1
sudo cat /var/log/cron/snapshot.log
Viewing your backup files
If you have any questions or comments, please leave them in the comment field below.
For troubleshooting support, be sure to check out the WordPress Cloud Hosting Support Group on Facebook.