Page 1 of 1

mysqldump to another server using ssh

Posted: Sun Mar 08, 2009 8:55 pm
by ryclem
I have a problem that is frustrating the crap out of me…. I’m trying to do a mysqldump to another server (obviously don’t want to keep the backup on the same server)…. I’m trying to do this through PHP like the following:

$remote_backup = “/usr/bin/mysqldump $dbname –opt -h$host -u$user -p$password | gzip -c | ssh user@111.222.333.444 ‘cat > /home/httpd/vhosts/domain.com/backups/2009-03-07-15-13-56.gz’”;
system($remote_backup);

This not working from PHP, however when I run it direct from SSH shell below it works perfectly.

/usr/bin/mysqldump $dbname –opt -h$host -u$user -p$password | gzip -c | ssh user@111.222.333.444 ‘cat > /home/httpd/vhosts/domain.com/backups/2009-03-07-15-13-56.gz’

I setup key authentication so that SSH does not prompt for a password, but it is still not working from PHP.

What am I doing wrong? I’ve spend tons of time searching for this solution…. any help would be greatly appreciated.

Thanks,
Ryan

Re: mysqldump to another server using ssh

Posted: Thu Mar 19, 2009 1:09 am
by jaoudestudios
Why are you doing it through php, you are adding more comlication to the mix. Just do it through a shell/bash script and a cron job.

If you want to be even fancier, you could setup an svn subversion repo server on your other server and checkin/commit to svn with each mysqldump, that way you will have a history too - just incase you get spammed and you dont know about it for a few days, you can jump back in time :) to any day.