Whooked
 

Go Back   Whooked > Technology > Programming

Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old May 6th, 2008
Rokudaime's Avatar
Member
 
Join Date: Apr 2008
Location: Somewhere in the path of life
Posts: 68
Thanks: 0
Thanked 3 Times in 1 Post
WPoints: 0.00
Donate
Rokudaime is on a distinguished road
Default How to backup your database automatically

Automated daily backups shouldn't be a chore and will save you many headaches in the future. This is the simplest script I've been able to find.

Backup script:

Code:
/usr/bin/mysqldump -hDBHOST -uDBLOGIN -pDBPASSWORD DATABASE | gzip > /MY/BACKUP/LOCATION/BACKUPNAME.sql.gz
Open up notepad then copy and paste the above code in a blank file to edit.

Replace:
DBHOST = Your database server (usually localhost, consult your host if you are unsure).
DBLOGIN = Username for your database.
DBPASSWORD = Password for database username.
DATABASE = The database you wish to backup.
/MY/BACKUP/LOCATION/ = Location you wish the backup to be saved (I recommend saving it below the root directory so it cannot be downloaded or edited by public users). Don't forget to CHMOD the directory to atleast 666 (writable).
BACKUPNAME = The name you wish to have the backup saved as in the directory listed.

After you've edited this to your liking save it to your PC and rename the file and remove the extention (you can name this anything but for this example I will be using mybackup).

Now upload the file to your site below the root directory (remember, no extention, so if after you upload it it shows with a .txt extension remove it). Change the permission of the file to allow it to be executed. CHMOD 755 will do the trick.

Now go to cPanel and go to the Cron Jobs area and create a cron job pointing to the file you uploaded.

Example:

Code:

Command to run: /MY/DIRECTORY/mybackup
Minutes: 15
Hours: 1 = 1 AM
Day(s) = Every Day
Month(s) = Every Month
Weekday(s) = Every Week Day

Replace /MY/DIRECTORY/ with the location you uploaded your "mybackup" script. If you are using cPanel and uploaded the file in your home directory then you would put: /home/YOURCPANELLOGIN/

This will create a daily backup of your database every day at 1:15AM server time. You can adjust your time accordingly, I just happen to know when the majority of my automated tasks run and when my site has the least amount of traffic so I try to schedule my backups so that it will not conflict with other tasks and to increase the chances of getting the most updated info before the increase of traffic.

The problem with this is that each day at 1:15AM it will right over the previous day's backup.


Keep in mind:
*This is only a LOCAL backup. If your server dies all is lost, be sure to download the backups to your PC to have both local and offsite backups!
*If your site is hacked or your database gets corrupt, disable your cronjob so that any current backup you have is not overwritten.
*Relying on a single backup is risky. It is best to have a daily backup, weekly backup, and monthly backup. If you have plenty of space (or a small database) then have as many local and offsite backups as possible to lessen the damages done if you need to restore.
__________________
Reply With Quote
The following 3 members thank Rokudaime for this post:
Josh (May 29th, 2008), kitsrock (May 20th, 2008), sanjiv (May 28th, 2008)
  #2 (permalink)  
Old May 8th, 2008
Whooked is my sex!
 
Join Date: Apr 2008
Location: Sydney, Australia
Posts: 124
Thanks: 2
Thanked 1 Time in 1 Post
WPoints: 0.00
Donate
Zodiac is on a distinguished road
Send a message via MSN to Zodiac Send a message via Yahoo to Zodiac
Default

This would be really good for people with forums...right?

~Zodiac
__________________


Add me on msn - turk_2_b_seen@hotmail.com

Reply With Quote
  #3 (permalink)  
Old May 8th, 2008
.Kamikaze is teh s3x !
 
Join Date: Apr 2008
Location: mmokings.net
Posts: 54
Thanks: 3
Thanked 2 Times in 2 Posts
WPoints: 1.00
Donate
.Kamikaze is on a distinguished road
Default

Yeah..it will help ppl with forums, ex: if a site gets ddos and all the files get deleted or something..
Reply With Quote
  #4 (permalink)  
Old May 8th, 2008
Rokudaime's Avatar
Member
 
Join Date: Apr 2008
Location: Somewhere in the path of life
Posts: 68
Thanks: 0
Thanked 3 Times in 1 Post
WPoints: 0.00
Donate
Rokudaime is on a distinguished road
Default

Yes this is good for backing up forums
__________________
Reply With Quote
  #5 (permalink)  
Old May 27th, 2008
sanjiv's Avatar
Web Designer
 
Join Date: Sep 2007
Posts: 1,469
Thanks: 75
Thanked 17 Times in 15 Posts
WPoints: 0.00
Donate
sanjiv is on a distinguished road
Default

thx m8
will try it
__________________

Reply With Quote
  #6 (permalink)  
Old May 27th, 2008
Chris_'s Avatar
PHP Dev
 
Join Date: Mar 2008
Location: America
Posts: 109
Thanks: 0
Thanked 9 Times in 9 Posts
WPoints: 0.00
Donate
Chris_ is on a distinguished road
Send a message via MSN to Chris_
Default

Quote:
Originally Posted by .Kamikaze View Post
Yeah..it will help ppl with forums, ex: if a site gets ddos and all the files get deleted or something..
How would a DDoS attack delete files?
Reply With Quote
  #7 (permalink)  
Old May 28th, 2008
sanjiv's Avatar
Web Designer
 
Join Date: Sep 2007
Posts: 1,469
Thanks: 75
Thanked 17 Times in 15 Posts
WPoints: 0.00
Donate
sanjiv is on a distinguished road
Default

I think he means a server attack.

Can i put
Code:
/usr/bin/mysqldump -hDBHOST -uDBLOGIN -pDBPASSWORD DATABASE | gzip > /MY/BACKUP/LOCATION/BACKUPNAME.sql.gz
in command to run in Cron Jobs?
__________________


Last edited by sanjiv; May 28th, 2008 at 08:08 AM.
Reply With Quote
  #8 (permalink)  
Old May 29th, 2008
Member
 
Join Date: May 2008
Posts: 28
Thanks: 0
Thanked 5 Times in 4 Posts
WPoints: 1.00
Donate
zaidihacker is an unknown quantity at this point
Default

yap this is nice script and we all need but if its working
Reply With Quote
  #9 (permalink)  
Old May 29th, 2008
sanjiv's Avatar
Web Designer
 
Join Date: Sep 2007
Posts: 1,469
Thanks: 75
Thanked 17 Times in 15 Posts
WPoints: 0.00
Donate
sanjiv is on a distinguished road
Default

course it will work but do u mean yap mine will work?
__________________

Reply With Quote
  #10 (permalink)  
Old May 29th, 2008
Master potato-peeler
 
Join Date: May 2008
Posts: 36
Thanks: 8
Thanked 0 Times in 0 Posts
WPoints: 0.00
Donate
Josh is on a distinguished road
Send a message via MSN to Josh
Default

This looks pretty useful, so, thanks! I've lost countless databases -- not on forums -- simply by pressing "delete" by mistake, so I'll have to start bothering to back-up.
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 07:20 PM.