In the world of website administration, there are very few things that take priority over having a recent backup of your website. It can make a world of difference when things go wrong, whether your site is hacked, or a recent update has killed it, either way, you need it back and you need it quick. If you have a small website, then you probably make your backups manually, but what if your website has 100’s of thousands of users? Making Manual back might become a little too time consuming.
This is where a little something called cron-jobs come in.
You can use cron-jobs to make your server execute a script at a pre-defined time of the day and week. You can make it daily, weekly, monthly, bi-monthly…well, you get the drift. So how does this relate to backup? Well, we know that PHP is a powerful programming language, but in combination with cron-job, it can be used in an even more powerful to automate the process of making a back-up.
Note: For the scope of this article, I will only cover database backup, rather than full website backup. My logic being, that the databases are the main dynamic component. If you change other files, you generally would have a copy of it left on your computer anyways, but nevertheless, you should make period manual backups of simply the html/php/etc files as well.
So what do you need?

Server Requirements:
- Support for Cron-job
- A Backup script of some sort
- An example can be found here
So let’s dive into this with a step by step guide:
Step 1) Grab a script like the one mentioned above and place it somewhere above the “public_html†folder, or “wwwâ€, folder. So, you can either give them their own folder in the top level, or just place the script there directly, just so it’s distinguished from everything else. The script will most likely require the following pieces of information for configuration: database name, database username, database table, and database password.
Step 2) Open up whatever control panel interface you have (shown is cPanel since it is the most common):

Step 3) Get your base URL path, so we can put it in the cron-tab. Go ahead and put your script file here, or in a folder (other than “WWW†or “Public_HTML†). Your base URL will most likely be something like /home/username/cronjob.sh (cronjob.sh is your backup script).
Step 4) Go to the cron-job area in your control panel, again, we use cPanel as an example and go to the standard section.

Step 5) Put in the path to your script in the command area and select when you want it executed and how often, as illustrated in the image below. You’ll have to fill out the highlighted portions.

Step 6) Sit back, relax, and let the server do your backups for you from here on.
And you have just automated the process of making backups. With the amount provided by services like GMAIL, e-mail should be fairly convenient (unless you have a very huge site, in which case I’m sure you can arrange an inbox with a much bigger storage capacity). Alternatively, you can find scripts that will use FTP to transfer the backups to a remote server.
Additional Resources:
- Script used as an example.
- A good resource for learning basic cron commands.
- Another tutorial that deals with the nature of automating backups
- Another good resource for people wanting to learn about cron-jobs.
No related posts.



I had backups set with GoDaddy, only to find out that I could only access my backup through my server – so if the server went down, I couldn’t get to my backup! I also couldn’t get a single file out of a backup – it was all or nothing.
Frustrated, I wrote my own server backup script which saves to an FTP location or Amazon S3. It handles website backups as well as MySQL databases, and the MySQL data can be extracted to run a single query, if necessary.
I precisely had to appreciate you yet again. I’m not certain the things that I might have tried in the absence of those ways shown by you regarding such subject. This was an absolute frightful scenario in my view, but understanding this professional avenue you resolved the issue took me to leap with joy. I will be grateful for the assistance and thus hope that you are aware of a great job you are doing instructing some other people through the use of your web page. Probably you have never encountered all of us.
Dudes! This isnt to bad, i am browing your blog now and wanted to say Thank you for taking your time to write this