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

GaryW

Active Member
Apr 27, 2004
31
0
156
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! :)
 

GaryW

Active Member
Apr 27, 2004
31
0
156
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
 

jester.ro

Well-Known Member
PartnerNOC
Feb 6, 2004
304
0
166
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)
 

GaryW

Active Member
Apr 27, 2004
31
0
156
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?
 

GaryW

Active Member
Apr 27, 2004
31
0
156
what cronjob line should I use to run this bash file of yours?
 

sleddog

Active Member
Jun 13, 2004
44
0
156
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.
 
Last edited: