Nov 8, 2009

How To Backup MySQL DBs Regularly Using Cron Jobs

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Networking

How To Backup MySQL DBs Regularly Using Cron Jobs

little0run
I remember seeing a guide on setting up a cron job that would back up a MySQL database and e-mail it to a given e-mail address, w/o a php file (I think) does anybody know how to do this or where to find that guide? I can't find it now... sad.gif

Comment/Reply (w/o sign-up)

miCRoSCoPiC^eaRthLinG
QUOTE(little0run @ Oct 29 2005, 10:07 AM)
I remember seeing a guide on setting up a cron job that would back up a MySQL database and e-mail it to a given e-mail address, w/o a php file (I think) does anybody know how to do this or where to find that guide?  I can't find it now... sad.gif
*




    [/tab]It should be quite easily done with the command crontab - which creates the cron table for the current user. Crontab takes the following parameters:
crontab filename[tab]    [/tab]Install filename as your crontab file.
crontab -e[tab]    [/tab]Edit your crontab file.
crontab -l[tab]    [/tab]Show your crontab file.
crontab -r[tab]    [/tab]Remove your crontab file.

[tab]You simply go about editing/creating a cron file. But first you need to check whether you have a cron file at all. You do that by issuing:
CONSOLE
shell> crontab -l
no crontab for root

As you can see, the message says that there's no cron file for me yet.

    [/tab]So I go about creating a cron file by simply using the -e option (edit)
CONSOLE
shell> crontab -e
no crontab for root - using an empty one

...

Your standard editor opens up a blank file. Most likely it's going to be openend up in the VI editor, which is default on most systems.

[tab]Now you need to put in the actual data. Each entry in a crontab file consists of six fields, specified in the following order:

minute(s) hour(s) day(s) month(s) weekday(s) command(s)

The fields are separated by spaces or tabs. The first five are integer patterns and the sixth is the command to be executed. The following table briefly describes each of the fields:
QUOTE
Field    [/tab]Value[tab]Description
minute    [/tab]0-59[tab]The exact minute that the command sequence executes.
hour    [/tab]0-23[tab]The hour of the day that the command sequence executes.
day    [/tab]1-31[tab]The day of the month that the command sequence executes.
month    [/tab]1-12[tab]The month of the year that the command sequence executes.
weekday    [/tab]0-6[tab]The day of the week that the command sequence executes. Sunday=0, Monday = 1, Tuesday = 2, and so forth.
command    [/tab]TEXT[tab]The complete command sequence variable that is to be executed.

Source: Linux manpages


Each of the patterns from the first five fields may either be an asterisk (*) (meaning all legal values) or a list of elements separated by commas.

An example for backing up all the mysql databases at 12 midnight everyday would be:
0 0 * * * mysqldump -u YourUserName -pYourPassword --databases mydb1 mydb2 > /home/backups/mysqlbackup.sql

That's what should go into the crontab file in the editor. This will create regular backups of the databases mydb1 and mydb2 at sharp 12 midnight everyday of the month/year and dump the backup into a file called mysqlbackup.sql located in the /home/backups directory.

Next command would be to mail it to yourself. You can use the standard mail command to mail the file to yourself. Say do it a minute later than the backup command.
1 0 * * * mail ...

errr.. I forgot the exact syntax of the mail command. Maybe someone else can help you with it - or when I figure it out, will let you know biggrin.gif

Hope this helps.
Regards,
m^e

 

 

 


Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : Backup Mysql Dbs Regularly Cron Jobs

  1. Backup DNS For Domain - (4)
  2. Free Secondary Dns/backup Name Server - Enterprise Secondary DNS (0)
    Free Secondary DNS Provider List http://www.gamesaga.net/secondary_dns/ dnsmadeeasy.com
    twisted4life.com dnspark.net editdns.net everydns.net ...... ...
  3. Site Backup - (3)
    I was wondering if there was any way to backup one site to another site on a different server. So
    if the first site goes down you could redirect users to the second site and it would be the same. I
    looked through the backup in cpanel and it did not seem like it has this functionality. If anyone
    knows of a script that can do this it would be awesome. Thank You...



Looking for backup, mysql, dbs, regularly, cron, jobs

See Also,

*SIMILAR VIDEOS*
Searching Video's for backup, mysql, dbs, regularly, cron, jobs
advertisement



How To Backup MySQL DBs Regularly Using Cron Jobs

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com