Setup Automatic Backups for Websites on Google Cloud

11

In this post, you will learn how to configure setup automatic backups daily 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.

There are 5 steps in this tutorial:

  • 1. Enable Compute Engine access
  • 2. Clone automatic backups script
  • 3. Create cronjob to automate script
  • 4. Enable logging for cronjob
  • 5. Optional Configurations

1. Enable Compute Engine access

 

At first, from your Google Cloud dashboard, select the hamburger menu in the upper-left corner of the screen then operate to Compute Engine > VM Instances.

Setup Automatic Backups

From your Virtual Machine (VM) instances page, click on the VM instance that is running your website.

Setup Automatic Backups

At the top of the VM instance settings page, click the Stop icon, and wait for your instance to shutdown. After it has successfully shut down, click on the Edit icon.

Setup Automatic Backups

Scroll to the very bottom of the page to the section titled API Access Scopes. From here, change the Compute Engine setting to Read Write, then click the Save button.

Setup Automatic Backups

Lastly, scroll back to the top of the page and click the Start icon to restart your VM instance, then click the back arrow icon to return to your VM instances dashboard.

Setup Automatic Backups

2. Clone automatic backup script

From your VM instance dashboard, click on the SSH button to connect to the VM instance that is running your website.

Setup Automatic Backups

Now that you’re connected to your VM instance, copy and paste the entire script below into the SSH terminal in order to clone the automatic backup script.

Setup Automatic Backups

3. Create cronjob to automate script

Now copy and paste the command below to create a new crontab file.

Setup Automatic Backups

In your crontab file, copy and paste the script below at the very bottom of your crontab file, then press CTRL + X, then Y, to save and exit the crontab file.

Setup Automatic Backups

4. Enable logging for cronjob

Copy and paste the script below to create a log file which will create a new record every time a new backup file is created.

Setup Automatic Backups

Copy and paste the script below to create a logrotate file, which will ensure that our log file never gets too big.

Setup Automatic Backups

Finally, paste the script below into the logrotate file, then press CTRL + X then Y to save the file.

Setup Automatic Backups

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.

In the example above, the -d flag is is added to the script to instruct the system to save a total of 30 backups instead of the default 7. You can replace 30 with the number of backups you want to be saved.

Setup Automatic Backups

Testing the automatic backup script

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

Execute the code below in your SSH terminal to ensure that your cronjob script is configured properly.

Setup Automatic Backups

Wait a minute or so, then execute the command below to check the status of the backup in your log file.

Setup Automatic Backups

If the setup automatic backups file was generated successfully, you will see an output similar to the image above.

Viewing your backup files

To find your uploaded or backup files, just press on the snapshot link in the sidebar menu on Google Cloud.

Setup Automatic Backups

If your configuration is working properly, you will see a new backup (snapshot) file.

Setup Automatic Backups

 

See More Related Articles :>>>>>

Tips to Speed Up On Website Inside Optimize JavaScript Code

Tips When Adopting Web Hosting Company

Setup Free SSL for WordPress on Google Cloud 

 

Leave A Reply

Your email address will not be published.