Auto backups on Google Cloud

How to Setup Automatic Backups for Websites on Google Cloud Platform

Configuring automatic backups of your web sites arrangement by no arrangement having to fear about shedding your web sites’s data in the case of an emergency.

On this tutorial you’ll learn to configure automatic day after day backups of your web sites on Google Cloud by configuring an automatic-backup script.

The automated backup script creates a unusual backup (snapshot) of your web sites in accordance to predefined specifications which you’ll define in this tutorial.

configuring disk snapshot backups google cloud
The script will automatically delete the oldest backup file when a unusual one is created, that arrangement that the total number of backups accessible at any given time will by no arrangement exceed 7.

Getting started

Earlier than citing this tutorial, it is a ways needed that you just reserve a static IP take care of to your VM occasion. Whilst you happen to don’t reserve a static IP take care of forward of starting this tutorial, Google Cloud will automatically set up a unusual IP Deal with to your VM occasion when it restarts.

Whilst you happen to haven’t yet launched a arena on Google Cloud, test out the following beginner tutorials for instructions on how to install WordPress on Google Cloud:

  1. The steady arrangement to Install WordPress on Google Cloud (Click-to-deploy)
  2. The steady arrangement to Configure a Enviornment Title for WordPress on Google Cloud

There are 5 steps in this tutorial:

automatic backups google cloud
From your Google Cloud dashboard, click on the hamburger menu in the greater-left nook of the show conceal then navigate to Compute Engine > VM Instances.
automatic backups google cloud compute engine
From your VM circumstances page, click on on the VM occasion that is running your web sites.
automatic backups google cloud compute engine
At the tip of the VM occasion settings page, click on the Close icon, and take a seat up for your occasion to shutdown. After it has efficiently shutdown, click on on the Edit icon.
automatic backups google cloud compute engine
Scroll to the very bottom of the page to the fragment titled API Get entry to Scopes. From here, substitute the Compute Engine atmosphere to Read Write, then click on the Assign button.
automatic backups google cloud compute engine
Lastly, scroll relief to the tip of the page and click on the Inaugurate icon to restart your VM occasion, then click on the relief arrow icon to come to your VM circumstances dashboard.
automatic backups google cloud compute engine
From your VM occasion dashboard, click on on the SSH button to join to the VM occasion that is running your web sites.
automatic backups google cloud compute engine
Now that you just’re connected to your VM occasion, copy and paste your total script under into the SSH terminal in uncover to clone the automatic backup script.

wget https://uncooked.githubusercontent.com/jacksegal/google-compute-snapshot/grasp/gcloud-snapshot.sh

chmod +x gcloud-snapshot.sh

sudo mkdir -p /opt/google-compute-snapshot

sudo mv gcloud-snapshot.sh /opt/google-compute-snapshot/
automatic backups google cloud compute engine
Now copy and paste the present under to build a unusual crontab file.
sudo crontab -e
automatic backups google cloud compute engine
For your crontab file, copy and paste the script under on the very bottom of your crontab file, then press CTRL + X, then Y, to place and exit the crontab file.
10 18 * * * /opt/google-compute-snapshot/gcloud-snapshot.sh >> /var/log/cron/snapshot.log 2>&1
automatic backups google cloud compute engine
Reproduction and paste the script under to build a log file which will build a unusual sage at any time when a unusual backup file is created.

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
automatic backups google cloud compute engine
Reproduction and paste the script under to build a logrotate file, which will seemingly be sure that that that our log file by no arrangement will get too mountainous.
sudo nano /and heaps others/logrotate.d/cron
automatic backups google cloud compute engine
At ultimate, paste the script under into the logrotate file, then press CTRL + X then Y to place the file.

/var/log/cron/*.log {

day after day

missingok

rotate 14

compress

notifempty

build 664 root adm

sharedscripts
}

Defining the total number of backups to place

On this tutorial, you configured the intention to place a crammed with seven backups. You most more than seemingly can substitute the total number of backups to whatever you need, merely by incorporating the -d flag.

configuring backups websites on google cloud
Within the instance above, the -d flag is is added to the script to reveal the intention to place a crammed with 30 backups as a substitute of the default 7. You most more than seemingly can substitute 30 with the number of backups you’re looking out for to be saved.
10 18 * * * /opt/google-compute-snapshot/gcloud-snapshot.sh -d 30 >> /var/log/cron/snapshot.log 2>&1

Sorting out the automatic backup script

You most more than seemingly can test whether the automatic backup script is working by executing the backup script in your SSH terminal.

automatic backups google cloud
Construct the code under in your SSH terminal to make certain that that that your cronjob script is configured well.
/opt/google-compute-snapshot/gcloud-snapshot.sh >> /var/log/cron/snapshot.log 2>&1
automatic backups wordpress google cloud
Wait a minute or so, then stay the present under to test the set of the backup in your log file.
sudo cat /var/log/cron/snapshot.log
automatic backups wordpress google cloud
If the backup file used to be generated efficiently, you’ll glimpse an output such as the image above.

Viewing your backup data

automatic backups google cloud gaze backup data
To gaze your backup data, click on on the snapshot hyperlink in the sidebar menu on Google Cloud.
automatic backups google cloud gaze backup data
In case your configuration is working well, you’ll glimpse a unusual backup (snapshot) file.

Closing thoughts

Whilst you happen to’ve any questions or comments, please fling away them in the comment field under.

Special as a result of Jack Segal for creating the automatic snapshots script.

For troubleshooting toughen, be sure that to test out the WordPress Cloud Web hosting Strengthen Neighborhood on Facebook.

 

Zulkifl Agha

View posts by Zulkifl Agha
Data Scientist currently providing services as a Word Press developer, designer and programmer; normally deals in Artificial Intelligence, Big Data, Machine Learning and Neural Networks in general "Data Science". I develop scrappers for Individual site owners and for companies to extract data of any website and display it on their project with various variations.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top