Previously, I have shown you how to schedule a database backup using cron job and email yourself the database file, but if you have a big database, you will find that the emailing method might not work as well as you want it to be. A good alternative to this is to upload your database to Dropbox. Here is a simple script that you can use to backup your database to Dropbox.
1. Download the script here.
2. Extract the zip file. Open the backup.php with a text editor and edit your database and Dropbox credential.
Optionally, you can create a backup folder in your Dropbox and insert the name of the folder to the backup.php. Your database will then be backed up to this folder.
3. Save and close the file. Upload the whole backup folder to your server. Note the uploaded location relative to the server root.
4. If you are using cPanel for your web hosting, log into it and go to the cron job section.
5. Create a new cron job. You can set the time and frequency to backup the database. Under the command field, copy and paste the following command:
/usr/bin/php -q /path-to-backup-folder/backup/backup.php
Change the “path-to-backup-folder” to the location (relative to the server root) where you upload the backup folder.
6. Save the cron job.
That’s it. Now, your server will backup your database and upload it to your Dropbox account.
Note: This is a generic method for backing up any database on a Linux server. However, if you are using WordPress, there are plugins that you can use to back up your database to Dropbox. One thing to note: if you have a big database, using the plugin to backup your database will use a lot of system resources and and might slow down (or even crash) your WordPress site if your server is not up to par.
Image credit: Backup word on white keyboard by Big Stock Photo.