Thanks for the help all - I'll try what you mentioned.
Mosher
"Chuck Anderson" <websiteaddress@seemy.sig> wrote in message
news:xtCdncHaEu3thOXfRVn-gw@comcast.com...[color=blue]
> Chris Hope wrote:
>[color=green]
>>Mosher wrote:
>>
>>[color=darkred]
>>>Hi all, I am wanting to automatically do dump of a mysql database
>>>nightly using cron and some kind of script that will email the whole
>>>db structure to me (as an attachment or as plain text in my email) -
>>>including the data in the db. So, if the db was ever lost, I could go
>>>to my email, find the dump and copy and paste it into the mysql db
>>>again.
>>>
>>>Does anyone know how to do this in PHP or of a premade (and free)
>>>script out there, preferably written in PHP?
>>>[/color]
>>
>>Dump it using mysqldump into a text file using one of the system() or
>>exec() type function calls, then either attach the resulting text file
>>to your email or make it the body of the message.
>>
>>[/color]
> I'm no great Php expert, probably not perfect Php, but here's the function
> I use in my script:
>
> ////////////////////////////////////////////
> function create_db_backup ($path, $tables = "")
> {
> $filename=$DBNAME . "_backup" . "_" . date("n-j-y_H-i-s") .
> ".sql";
>
> system("mysqldump --add-drop-table -u $USRNAME -p $PASSWRD $DBNAME $tables[color=green]
> > $path/$filename", $result);[/color]
>
> system ("gzip $path/$filename", $result);
>
> $gzname = $filename . ".gz";
>
> return $gzname;
> }
>
> $path is the directory I save backups to.
>
> $tables is optional. If empty, mysqldump will backup all tables, otherwise
> it's a list of tables to backup (separated by a space, e.g." table1 table2
> table3" - no quotes).
>
> I use --add-drop-table because it seems like the simplest sql file to use
> for a restore.
>
> Finally, I gzip it to make it smaller.
>
> Now all you have to do is mail it to yourself. I use Phpmailer.
>
> --
> *****************************
> Chuck Anderson • Boulder, CO
>
http://www.CycleTourist.com
> Integrity is obvious.
> The lack of it is common.
> *****************************[/color]