Daily/weekly/monthly Mysql database backup with cron

Smart Mysql database backup with cron
Create and assign a DB user to the DB you want to backup with all privileges from your Cpanel >> Mysql section.
following is a simple script to take backup using cron. Just create the file, chmod it to 750 and execute it using cron.

#============================

#/bin/bash
/usr/bin/mysqldump –user=db_User –password=xyz –databases db_name | gzip > /home/foo/db_name-`date “+%Y%m%d%H%M”`.sql.gz

#============================

where,
db_user is your database user who has access on your database.
db_name is the database name you are scheduling backup for.
xyz is the actual password of above database user.
+%Y%m%d%H%M is the time stamp which will help to distinguish between backup date and time.
the backup destination in above example is “/home/foo/”

add following line in cron to take backup everyday at 23:00 and will store in separate file

0 23 * * * /PathToScript.sh

Security notes Note ::
1) Dont use the command directly in cron. Put the command in a file and execute that file in cron.
2) I asked to chmod to 750 so that other will not be able to view your files.
If the file is readable by others anyone may view it and get your DB access very easily.

Be Sociable, Share!

412 thoughts on “Daily/weekly/monthly Mysql database backup with cron”

  1. Paying for college these days is a very expensive proposition. The final
    portion of the FAFSA to evaluate your financial aid eligibility is called
    the EFC, or Expected Family Contribution. To study criminal justice is to ponder God’s purpose in establishing civil authorities.

  2. A fascinating discussion is definitely worth comment.
    I do believe that you ought to write more on this issue,
    it might not be a taboo subject but generally people do not speak about these issues.
    To the next! Best wishes!!

  3. I rarely comment, but i did a few searching and wound up here Daily/weekly/monthly Mysql database backup with cronRegencyHost Blog | RegencyHost Blog.
    And I do have a couple of questions for you if you don’t mind.

    Could it be only me or does it look like a few of these responses look
    like they are coming from brain dead folks? 😛 And, if
    you are posting at additional places, I would like to keep up
    with everything new you have to post. Would you list of the complete
    urls of your public sites like your Facebook page,
    twitter feed, or linkedin profile?

  4. I blog often and I truly appreciate your content. This article has really
    peaked my interest. I am going to bookmark your website and keep checking for
    new information about once a week. I subscribed to your
    RSS feed too.

  5. obviously like your web-site but you have to test
    the spelling on quite a few of your posts. Many of them are rife with spelling
    issues and I to find it very troublesome to
    tell the reality then again I’ll surely come again again.

  6. Hello there I am so delighted I found your site, I really found you by
    error, while I was browsing on Google for something else, Regardless I am here
    now and would just like to say many thanks for a tremendous post and a all round exciting
    blog (I also love the theme/design), I don’t have time to go through it all
    at the moment but I have saved it and also added in your RSS feeds, so when I have time
    I will be back to read a great deal more, Please do keep
    up the fantastic job.

  7. Thanks , I have just been looking for information approximately this
    topic for a while and yours is the greatest I’ve discovered
    till now. However, what concerning the conclusion? Are you sure in regards to the supply?

Leave a Reply

Your email address will not be published. Required fields are marked *

Connect with Facebook

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>