Linux – Redirect output of thesqldump to scp

linuxlinux-networkingMySQLpipescp

I worked with a linux pro years ago who did this nifty trick. He could do a mysqldump but redirect the output to an scp/ssh connection rather than writing to disk. We utilised this quiet a bit where i used to work but I cannot remember how to do this anymore.

I'm now faced with the issue where my hard drive in my server is on it's last legs and is, for intensive purposes, permanently mounted as read only.

I was hoping to utilise this command line trickery to still be able to back up my databases on to a new server, since writing the dump to the local diska nd transferring it is clearly out of the question.

Is this actually little trick actually possible? If so what is the syntax?

I've since realised due the read only file system issue I'm experience I cannot even connect to mysql to do the dump. But your feed back was great and hopefully of use to someone else in the future

Best Answer

mysqldump dbname | ssh root@remoteserver.com "mysql -D dbname"

that should work :-)

Set up keys between the systems as well so you can do so w/o needing a login/pass :-)