I'm creating a snippet to be used in my Mac OS X terminal (bash) which will allow me to do the following in one step:
- Log in to my server via ssh
- Create a mysqldump backup of my Wordpress database
- Download the backup file to my local harddrive
- Replace my local Mamp Pro mysql database
The idea is to create a local version of my current online site to do development on. So far I have this:
ssh server 'mysqldump -u root -p'mypassword' --single-transaction wordpress_database > wordpress_database.sql' && scp [email protected]:~/wordpress_database.sql /Users/me/Downloads/wordpress_database.sql && /Applications/MAMP/Library/bin/mysql -u root -p'mylocalpassword' wordpress_database < /Users/me/Downloads/wordpress_database.sql
Obviously I'm a little new to this, and I think I've got a lot of unnecessary redundancy in there. However, it does work. Oh, and the ssh command ssh server
is working because I've created an alias in a local .ssh file to do that bit.
Here's what I'd like help with:
- Can this be shortened? Made simpler?
- Am I doing this in a good way? Is there a better way?
- How could I add gzip compression to this?
I appreciate any guidance on this. Thank you.