I’ve been using a linux testing machine for months now, a handy installation of ubuntu server called JeOS “Just Enough Operating System” , along with vm workstation , resulting in a very small footprint .. that edition is now deprecated, replaced by a minimum-install option of normal ubuntu server installation.
Anyways, Whenever i wanted to wrap up the website and test it in the real environment, i took sometime to export the database, then import it again at the host .. backup the testing files, tar it, and send it via wget or ftp .. then untar it at the host .. A lot of operations with waste time and a lot of human interaction ..
Few days ago, I’ve stumbled upon an article with the title “Tar Over SSH”, date goes back to 2005 , but it was really very helpful.
This article explains how to use a pipe a TAR command through SSH onto another server, and get it extracted there :
TAR -> SSH -> UNTAR
That was carried out using a command like this :
tar -zcf – {local_dir} | ssh {remote_user}@{remote.domain} tar -C {/path/to/remote/dir} -zxf -
I tried the procedure , and it was very impressive and successful everytime, used it couple of times, then thought : why wouldn’t i use that piping technique to transfer my databases too ?
I got the syntax going like this :
mysqldump -h{local_dbserver} -u{local_dbuser} -p{local_dbpass} {local_dbname} > – | ssh {ssh_username}@{your.domain} mysql -u{remote_dbuser} -p{remote_dbpass} {remote_dbname} < -
Note in the previous commands, that we use our command to send it’s output ( either .sql or .tar file } to stdout which is represented by the dash {-} , then connect to the remote host using SSH where we carry out the operation needed on that file ( output ) using stdin also represented by the earlier dash {-}.
I guess i’ll be making a script to transfer my whole website ( files and sqls ) at once, while configuring some static vars inside for my login and path info .. just when i have the time .. lol
UPDATE:
Walid suggested using bzip compression instead of gzip, been searching on the net for comparisons till i found jeremy’s “gzip vs bzip” .. and i came to the following results while compressing a 2.5GB sql file:
comp time comp. size decomp time gzip 14:31 349,736 0:55 bzip2 39:44 275,344 9:46
so, if you care more about Time,CPU and Memory you should go with GZIP , using the given commands .. but if you care more about bandwidth and space you should go with BZIP2 compression.
For me, and most of mediatemple® (gs) users, cpu is most cared for among other resources, because of their GPU “Grid Performance Unit” that limits your usage of CPU on their servers, so i guess i’ll stick to gzip for now.
To use bzip2 compression , just exchange the “-zcf” with “-jcf” , and the “-zxf” with “-jxf” .
Thanks for the nice ideas
Great site…keep up the good work.
I’m so glad I found this site…Keep up the good work I read a lot of blogs on a daily basis and for the most part, people lack substance but, I just wanted to make a quick comment to say GREAT blog. Thanks,
A definite great read…:)
-Bill-Bartmann