2010-10-13, 09:40 AM
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
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
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 +
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
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.shand 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 +