July 6, 2021 . 2 MIN READ
Scripting the backup
To make the cron job work, create a file called backup.sh and place the following code inside of it ::
#!/bin/sh
mysqldump -h DB_HOST -u DB_USER -p’DB_PASSWORD’ DB_NAME > YOUR_WEB_ROOT/db_backup.sql
gzip -f YOUR_WEB_ROOT/db_backup.sql
In the above script you will need to replace the portions in ALL CAPS with your actual information as follows ::
YOUR_WEB_ROOT
This is the absolute path to your files. You can find this path by clicking on Hosting, Cloud Sites, Features, and scrolling down. This will be the “Linux Path” listed there. An example would be: /mnt/target02/123456/www.domain.com (Note, the /web/content is not included in that path)
DB_HOST
Database Host an example would be mysql5-9.wc1 or mysql50-78.wc1.dfw1.stabletransit.com
DB_PASSWORD
The password on this database (note the single quotes and that there is no space between the -p and the single quote)
DB_USER
The database username (e.g.: 12345_username)
DB_NAME
The name of the database you are backing up (e.g.: 12345_database_name). Note that there is no parameter for this option unlike the previous examples (-h -p and -u respectively).
Place this file in your web root and create a cron job. Note, for step by step instructions on how to create a cron, Please visit our article on enabling and disabling cron jobs.
Put the name of the file, which, in our example is backup.sh in the “Command To Run Field”. Select Perl as the Command Language and then select the interval in which you wish to run your backup script.