[thelist] MySQL Backup Statement

Dan McCullough dan.mccullough at gmail.com
Fri Aug 5 10:45:16 CDT 2005


you need to probably specifiy the path to mysqldump, it would probably
be easier to output from mysqldump to a file then doing all the extra
stuff to grab the output.

so /<path/to/mysqldump --opt -u <user> -p<pass> <dbname> > /<backup
dir path>/backup.sql

you can even use this in the php code, your basically doing the same
thing except much longer in php and its a bit trickier to setup up php
in a cron, not too much just a little different.

php ######################################################

from
> $command = "mysqldump --add-drop-table --host=localhost --user=''
> --password='' dbname";

to
$command = "/<path/to/mysqldump --opt -u <user> -p<pass> <dbname> >
/<backup dir path>/backup.sql";
system($command);


#########################################################

somethings to remember.  permissions on the backup directory, pathes
to files, and if you dont know what the path to mysqldump is you can
do locate mysqldump from a shell.

its a pretty simple script

On 8/5/05, A Maynes <andrew at milords.com> wrote:
> I have just knocked this up but it doesn't seem to be cooperating can
> anyone help out
> 
> <?php
> 
> ob_start();
> 
> $username = "";
> $password = "";
> $hostname = "localhost";
> $sConnString = mysql_connect($hostname, $username, $password)
> or die("Unable to connect to MySQL");
> 
> //create a connection object
> $connection = mysql_select_db("dbname",$sConnString)
> or die("Could not select DB");
> 
> $command = "mysqldump --add-drop-table --host=localhost --user=''
> --password='' dbname";
> system($command);
> 
> $dump = ob_get_contents();
> ob_end_clean();
> 
> //The database dump now exists in the $dump variable... write it to a
> file using...
> 
> $fp = fopen("dump.sql", "w");
> fputs($fp, $dump);
> fclose($fp);
> 
> ?>
> 
> 
> Andrew
> 
> 
> > -----Original Message-----
> > From: A Maynes [mailto:andrew at milords.com]
> > Sent: 05 August 2005 15:12
> > To: 'Dan McCullough'; thelist at lists.evolt.org
> > Subject: RE: [thelist] MySQL Backup Statement
> >
> >
> > I'm not too fmailiar with shell which part would I put in the
> > .sh file?
> >
> > Could you point me to a shell tutorial for this setup please?
> >
> > Would I need to have gz installed?
> >
> > Andrew
> >
> >
> > > -----Original Message-----
> > > From: Dan McCullough [mailto:dan.mccullough at gmail.com]
> > > Sent: 05 August 2005 15:02
> > > To: thelist at lists.evolt.org
> > > Subject: Re: [thelist] MySQL Backup Statement
> > >
> > >
> > > you could so a simple shell script and cron it.
> > >
> > >
> > > #!/bin/sh
> > > #backup.sh
> > >
> > > date=`date -I`
> > > rm -f /var/backup/dbname-bak-*.sql.gz
> > /opt/mysql/bin/mysqldump --opt
> > > --quote-names -u <user> -p<pass> dbname
> > > | gzip > /var/backup/dbname-bak-$date.sql.gz
> > >
> > >
> > >
> > > On 8/5/05, A Maynes <andrew at milords.com> wrote:
> > > > I need to run a simple MySQL Backup statement without
> > > causing too much
> > > > strain on the server what would be the best method?
> > > >
> > > > I am thinking about running a cron to run a PHP script
> > which simply
> > > > dumbs the backup file in a DIR on a daily basis?
> > > >
> > > > Anyone have a pointer to the PHP code please
> > > >
> > > > Andrew
> > > >
> > > > --
> > > >
> > > > * * Please support the community that supports you.  * *
> > > > http://evolt.org/help_support_evolt/
> > > >
> > > > For unsubscribe and other options, including the Tip Harvester and
> > > > archives of thelist go to: http://lists.evolt.org Workers
> > > of the Web,
> > > > evolt !
> > > >
> > > --
> > >
> > > * * Please support the community that supports you.  * *
> > http://evolt.org/help_support_evolt/
> >
> > For unsubscribe and other options, including the Tip Harvester
> > and archives of thelist go to: http://lists.evolt.org
> > Workers of the Web, evolt !
> >
> >
> > --
> >
> > * * Please support the community that supports you.  * *
> > http://evolt.org/help_support_evolt/
> >
> > For unsubscribe and other options, including the Tip Harvester
> > and archives of thelist go to: http://lists.evolt.org
> > Workers of the Web, evolt !
> >
> >
> 
> --
> 
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
> 
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !
>


More information about the thelist mailing list