Usually after dumping a MySQL database with mysqldump
command I immediately tar/gzip the resultant file. I'm looking for a way to do this in one command:
So from this:
mysqldump dbname -u root -p > dbname.sql
tar czvf dbname.sql.tgz dbname.sql
rm dbname.sql
To something like this:
mysqldump dbname -u root -p > some wizardry > dbname.sql.tgz
Or even better (since I'm usually scp'ing the dump file to another server):
mysqldump dbname -u root -p > send dbname.sql.tgz to user@host
I'm running bash on debian.
You can't use tar in a pipe like this, and you don't need it anyway, as you're only outputting a single file. tar is only useful if you have multiple files.
If you are running this locally just use the following command to backup your database & zip it using gzip:
(Edit: fixed -c key)
Use a named pipe.
I use it all the time, it'a awesome.
http://en.wikipedia.org/wiki/Named_pipe
I wrote a quick script to suck down a remote mysql database. It uses mysql compression, gzip and ssh compression. Sucked down a multi GB database at an incredible rate.
A side benefit is that it requires no free space on the source database server, so you can use it to backup a database on a server with zero free disk space before going in an pruning your data.
Hope it helps somebody.
Use
pv
and monitor rate!Or, if you know the size (3GB), get an accurate estimate:
Try this:
Please not that I am in no way good at these things, I just combined 2 options on the web into one.
It may very well be better in some other way but this is a one-liner that works for me.
It does however require
ssh.keys
to be installed and accepted if you want to use it in scripts orcrontab
or alike.You can do like:
mysqldump --add-drop-table -h dbhost -u dbuser -p dbname (tablename tablename ... ) | gzip -c > wp.sql.gz
e.g.
mysqldump --add-drop-table -h localhost -u root -p wordpress | gzip -c > wp.sql.gz
I've been working on this bash script below that tries to put together all the good advices I've seen when it comes to dump/restore with mysql. It is targeted at remote operations.
Just reconfig vars and give it a try. :)
Features are:
What needs improvement:
I share this script here hoping it can be improved by the community. (best viewed with nano or other editor that colors the code)
--------------------------------- cut here ----------------------------------
You can also store your password in a config file and use this option --defaults-extra-file:
The config file can look like this: