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:
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###################### # BELOW ARE SOME REQUIRED SETTINGS. CONFIGURE THEM PROPERLY BEFORE USING # THE SCRIPT DBHOSTNAME=xxxxx.db.xxxxxxx.hostedresource.com DBUSERNAME=databaseusername DBPASSWORD=databasepassword DBNAME=databasename BACKUPFOLDER=$HOME/html/_db_backups/backupfolder DELETEFILES=Y DAILYBACKUP=Y NUMDAILYBACKUPS=6 WEEKLYBACKUP=Y NUMWEEKLYBACKUPS=4 MONTHLYBACKUP=Y NUMMONTHLYBACKUPS=2 #############END EDIT AREA######################
Here are the explanations for all the parameters in the code:
DBHOSTNAMEis 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.
DBUSERNAMEis the username to access the MySQL database. Just replace the word
databaseusernamewith your username. No quotes needed.
DBPASSWORDis the password to access the MySQL database. Just replace the word
databasepasswordwith your password database. No quotes needed.
DBNAMEis the MySQL database that needs to be backed up. Typically, in GoDaddy Linux Hosting this is the same as the
BACKUPFOLDERis the path to the folder where backups will be stored.
$HOME/htmlwill automatically put you in the hosting accounts root folder. GoDaddy MySQL databases are normally stored in the
_db_backupsfolder 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_backupsfolder 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
DAILYBACKUPis 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
WEEKLYBACKUPis 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
MONTHLYBACKUPis 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.