Is it possible to dump a database from a remote host through an ssh connection and have the backup file on my local computer.
If so how can this be achieved?
I am assuming it will be some combination of piping output from the ssh to the dump or vice versa but cant figure it out.
This would dump, compress and stream over ssh into your local file
ssh -l user remoteserver "mysqldump -mysqldumpoptions database | gzip -3 -c" > /localpath/localfile.sql.gz
Starting from @MichelFeldheim’s solution, I’d use:
$ ssh [email protected] "mysqldump -u user -p database | gzip -c" | gunzip > db.sql
ssh -f [email protected] -L 3306:server.com:3306 -N
mysqldump -hlocalhost > backup.sql
assuming you also do not have mysql running locally. If you do you can adjust the port to something else.
The script allows you to fetch a database dump from a remote host with or without
SSH and optionally using a
.env file containing environment variables.