Home » Blogging » Automatic MySQL database backup on GoDaddy shared hosting

Automatic MySQL database backup on GoDaddy shared hosting

GoDaddy is one of the most widely used domain and hosting provider. The offer hosting plans as low as $1 per month. In this post, I will provide a detailed explanation of how to create automatic MySQL database backup on GoDaddy’s Linux shared hosting. Please note that this method works only on Linux hosting. Each hosting account comes with one or more MySQL databases. And if you are a webmaster you know how critical it is to backup your database. Setting up automatic MySQL database backup is one way to backup your database without any effort from the webmaster. Enough said, let us now look at how to automatically backup MySQL database daily, weekly, and monthly using a bash script. Don’t worry you do not have to write any codes. This tutorial will provide with beginner-level instructions to achieve this.

What this script will do?

The script I will be providing in this guide will do automatic MySQL database backup by:

  • Creating a automatic MySQL database backup daily
  • At the end of the week, creating a weekly backup
  • At the end of the month, creating a monthly backup
  • Storing backups as compressed files to save space (upto 90% space-saving)
  • Deleting old daily, weekly, and monthly MySQL database backups – lets you define what is old

It is completely customizable without the need for any coding knowledge. In addition I have provided pictures at each step to guide you through the process. If you do not have a GoDaddy hosting account yet, this might be time to make use of the exclusive offer above.

Download Automatic MySQL Database Backup Script

The first step is to download the bash script I have written for you by clicking the button below:

Automatic MySQL Database Backup Script
(Click here to see the full code)

After downloading, open the script with Notepad++ or other code editors. Opening the code in Windows Notepad, WordPad or Word does not process symbols well and will cause the following error when the script runs:

^M:bad interpreter:No such file or directory

If you see the above error, your first attempt should be to fix the symbols such as ` and ‘ in the code using Noteplad++.

Edit the Bash Script

This script is written with comments (lines that start with a #) for everything that requires your input. It is divided into two sections. One you will have to edit before the script works and other that you should not edit if you do not know what you are doing. For the script to work all you to do is find the section below and provide some basic details. Open the script in Notepadd++ and edit it as shown below:

#############BEGIN EDIT AREA######################


#############END EDIT AREA######################

Here are the explanations for all the parameters in the code:

    • DBHOSTNAME is the host name of the host that hosts yours MySQL database. You can get this from GoDaddy. Just replace the entire contents after = with your database host name.
    • DBUSERNAME is the username to access the MySQL database. Just replace the word databaseusername with your username. No quotes needed.
    • DBPASSWORD is the password to access the MySQL database. Just replace the word databasepassword with your password database. No quotes needed.
    • DBNAME is the MySQL database that needs to be backed up. Typically, in GoDaddy Linux Hosting this is the same as the DBUSERNAME.
    • BACKUPFOLDER is the path to the folder where backups will be stored. $HOME/html will automatically put you in the hosting accounts root folder. GoDaddy MySQL databases are normally stored in the _db_backups folder within your base hosting folder. If the folder does not exist create it before running the script. You can also create a subfolder within _db_backups folder if you would like to backup the database to a separate folder. Alternatively, you can backup to an entirely different folder of your choice. Whatever you choose to do, ensure that the path is correctly specified.
    • DELETEFILES – Should the script delete older files based on the conditions you set (Y or N – uppercase letters only). Choosing Y will maintain only recent backups based on your settings here. Choosing N will keep all the backups from the past.
    • DAILYBACKUP – Do daily backups Y or N? (one uppercase letter only)
    • NUMDAILYBACKUPS – Number of recent daily backups to keep. The default is 6 (Sun-Fri) with Weekly backup on Sat. All previous backups will be deleted. This is meaningless unless DAILYBACKUP is set to Y.
    • WEEKLYBACKUP – Do weekly backups Y or N? (one uppercase letter only). Weekly backups are done on Saturdays.
    • NUMWEEKLYBACKUPS – Number of recent weekly backups to keep. The default is 4. All previous weekly backups will be deleted. This is meaningless unless WEEKLYBACKUP is set to Y.
    • MONTHLYBACKUP – Do monthly backups Y or N? (one uppercase letter only). Monthly backups are done on the last day of the month.
    • NUMMONTHLYBACKUPS – Number of recent monthly backups to keep. The default is 2. All previous monthly backups will be deleted. This is meaningless unless MONTHLYBACKUP is set to Y.

    As I said before, do not edit anything else other than the above unless you can understand the script and know what you are doing.

    Continue to next page to finish setting up automatic MySQL database backup on GoDaddy.

    We Are Hiring: Familiar with Media Streaming, HTPC, Home Server, Smart Home, and Home Automation topics? Write about it and earn money. No writing experience needed. APPLY HERE.

    Get 20% OFF with IPVanish VPN:

    ♦   Hide your browsing and streaming activity: No logs and no tracking
    ♦   Access geo-restricted content from anywhere
    ♦   Encrypt and anonymize: Kodi, Plex, Downloads, Personal Info
    ♦   Windows, Mac, Linux, Android, iOS, Router, and more.
    ♦   Money back guarantee - Sign Up Now

    About the author


    Anand is a self-learned computer enthusiast, a part-time blogger, and a Food Scientist by career. He has been blogging since 2010 on Linux, Ubuntu, Home/Media/File Servers, Smart Home Automation, and related HOW-TOs on htpcbeginner.com and smarthomebeginner.com.