MyBB Community Forums

Full Version: How to AUTO Backup your Database
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hello members,
I have seen many members get their forum installed, running smoothly and upgrading scripts...etc... but they get trouble when something gets wrong like their forum gets hacked, a moderator deleted many files or simply moved to anew host. At that time, what strikes first, how do i get my DB data back? oppps i should have taken backup of it Sad

If you don't have your DB backup at this stage, your all effort in building up of your forum/website gets lost... you may actually also need it when you upgrade your script.

but the problem is it's not possible to take backups manually every time, at-least daily. we need a method by which our DB gets backed-up automatically daily. I searched the whole net but couldn't found a nice tutorial in a simple way, so i decided to write this here.

(I am doing this because i was running phpbb3 for last 2.7 years and got hacked 2 times during this period, that's why switched to MyBB1.6 ; but i was quite lucky to get my DB back)

Anyways lets start, its quite easy.
1. We will need a script which will backup our db
2. We need to set a cron job which will run this script at regular intervals.

The script we will be using it is AutoMySQLBackup, you can download it here, it's free.

Now what this script will do:
Every day AutoMySQLBackup will run will dump your specified databases to the /backups/daily directory, it will rotate daily backups weekly so you should never have more than 7 backups in there..

Every Saturday AutoMySQLBackup will again backup the databases you have chosen but they will be placed into /backups/weekly, these will be rotated every 5 weeks so there should never be more than 5 backups in there..

Every 1st of the month AutoMySQLBackup will create a backup of all databases and place them into /backups/monthly. These will never be rotated so it will be up to you to do your own house keeping.

I would suggest taking a copy of these DB backups offline every month or two so that if you have a hard drive failure you will be able to restore your database..

Now the editing part, divided in two stages:

Part I
1. Now after downloading AutoMySQLBackup, place it in your web directory OUTSIDE public_html so that nobody can access it except yours ex. backups

2. Edit (at least) the following lines :-
USERNAME=dbuser (The user must have at least select privileges to the databases) PASSWORD=password
DBNAMES="DB1 DB2 DB3" (make sure to keep the quotes " " otherwise it won't work)
[In case you are using it for mybb forum db, it should be only the name of your forum db and i recommend to use it for that only]

3. Make the file executable :- chmod u+rwx (755)

Part II
Now we need to set a cron job which will run it at a specified time: (to know how to set it please read here)

I am just providing here the most important part, command line (only this which many of you don't know to write it).
In the cron command line, write
Quote:/bin/sh /home/[your username]/backups/automysqlbackup.sh
and save it to run once daily.

That's it ! You are done, now your daily, weekly and monthly DB backups will be backedup AUTOMATICALLY

Note: MyBB also have the facility to take backups automatically at a specified time using task manager, but i posted this because the DB dump stored here is outside public_html and also if something goes wrong with forum directory, you don't have to worry. (also it will not much slow down your forum while the backup is taken)

If you like this tutorial, don't donate... simply give some Rep + Toungue
Nice one I'm going to try this out Smile
do tell your feedback when you are done Smile
Hello drankur, I will try it I think you get today an feedback Wink

Greatings Boomreview.
sure, waiting for it Toungue
Thanks for the info but you can do all that via cron without the third party program

setup one cron job that uses

mysqldump -ec --add-drop-table -u{db_user} -p{db_pass} {db_name} > {saved_file.sql}

then run another cron 15 minutes later that uses

gzip -f1 -S .gz {saved_file.sql}

As long as you use your hosts control panel for the cron job, it will put the final file in your home folder.

No extra software, no extra permissions
thanks, but there is a very important feature in the 3rd part script i mentioned:

IT ROTATES BACKUP i.e: you will at anytime have:
1. 7 latest daily backup
2. 5 latest weekly backups
3. Monthly backups (12 in a year , you have to manage them urself)

all 3 in separate folders Smile

so no burden on the hosting space and no unnecessary clustering of dbs
I suppose that I am focused on my own dedicated server that has no issues with host space and such. I have daily, weekly and monthly full account backups, not just mysql.

I use the above cron jobs to backup daily mysql only so that if I mess something up its easier to restore
if you are happy than no need to use this one, let others try it out.
Also for me my FORUM DB is very imp (and i keep it separate) + i prefer files backup by ftp that's why using this. Smile
giving these errors

/home/xxxxxx/autodbu.sh: line 42: 5G: command not found
/home/xxxxxx/autodbu.sh: line 746: mutt: command not found

How to fix them?
Pages: 1 2