The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How do I generate a MySQL backup for a specified database in home directory?

Discussion in 'General Discussion' started by GaryW, Dec 17, 2004.

  1. GaryW

    GaryW Active Member

    Joined:
    Apr 27, 2004
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    How do I generate a MySQL backup for a specified database in home directory? Just like the 'Generate/Download a Full Backup' except only for one database - the only option that I see is being able to download the database, but I don't want that as well.

    I want to be able to create a backup of a specific database in the home directory and then receive an email when it is complete, just like the 'Generate/Download a Full Backup' option.

    Thanks in advance! :)
     
  2. jester.ro

    jester.ro Well-Known Member
    PartnerNOC

    Joined:
    Feb 6, 2004
    Messages:
    304
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Bucharest, Romania
    cPanel Access Level:
    DataCenter Provider
    i would use a cronjob

    look at mysqldump command, it's the best solution.
     
  3. GaryW

    GaryW Active Member

    Joined:
    Apr 27, 2004
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    how do I enter the password into the mysqldump line? because I believe that mysqldump normally prompts you for your password after entering a mysqldump line
     
  4. jester.ro

    jester.ro Well-Known Member
    PartnerNOC

    Joined:
    Feb 6, 2004
    Messages:
    304
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Bucharest, Romania
    cPanel Access Level:
    DataCenter Provider
    if you want to type this in command line,

    mysqldump -uroot -p

    it will ask you for password.

    if you want to use it in a script, you have to include it in the command

    mysqldump -uroot -pPASSWORD

    (no space between -p and the actual password)
     
  5. GaryW

    GaryW Active Member

    Joined:
    Apr 27, 2004
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    yep thanks I got that :) if I want to point to where the file should be, should I just use s/t like:

    mysqldump --opt -u user --password=password database > filename.sql

    or should I use a proper path for the filename.sql? where will it end up if I use it like this?
     
  6. sleddog

    sleddog Active Member

    Joined:
    Jun 13, 2004
    Messages:
    44
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Labrador, Canada
  7. GaryW

    GaryW Active Member

    Joined:
    Apr 27, 2004
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    what cronjob line should I use to run this bash file of yours?
     
  8. sleddog

    sleddog Active Member

    Joined:
    Jun 13, 2004
    Messages:
    44
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Labrador, Canada
    The format of a cronjob is:

    [min] [hour] [day of month] [month] [day of week] [command]

    Suppose you want the backup to occur at 6:00am every day, and your script is named mysql-backup.sh, your cron job would be like:

    Code:
    0 6 * * * /path/to/mysql-backup.sh
    The second item, [hour], is in 24-hour format. It starts with 0 and runs to 23. So this would run it at 11:30pm each day:

    Code:
    30 23 * * * /path/to/mysql-backup.sh
    The following would run it at 10:00am on the fifteenth day of the month:

    Code:
    0 10 15 * * /path/to/mysql-backup.sh
    You get the idea... :)

    If the command is a shell script or perl script, don't forget that it needs to be executable.
     
    #8 sleddog, Dec 28, 2004
    Last edited: Dec 28, 2004
Loading...

Share This Page