It’s the little things I like about Linux

Today I wrote some handy syncronization-scripts with the help of my freebsd-loving co-worker Marius. Till today I managed the syncronization of my local database with our production database with the help of phpMyAdmin.
An export of the 13mb sql file at the production server and an import at my machine took me at least five minutes (~2mb gzipped). Now take a look at this:

[hans@zommuntu:~]$ time ssh user@production_server "mysqldump --add-drop-table database_to_process -uUSER -pPASSWORD | gzip" | gunzip | mysql -uLOCALUSER -pLOCALPASSWORD database_name
real    0m4.389s
user    0m0.592s
sys     0m0.052s

Under five seconds! woot!!
Some words to explain this: First, you establish a ssh connection to the production_server. The gzipped dumped sql of the beloved database_to_process is transferred to your machine. Here it is gunzipped and written to your local database server into the database_name. The quotes are necessary as brackets to let the script know that the gzip command belongs to the ssh command.

Tags: , , , ,

Leave a Reply