Retrieve a MySQL backup from a remote Linux server
It's pretty simple, but I find myself doing it occasionally, and always forgetting the full invocation.
First SSH into the remote server, then dump out a dated backup:
mysqldump -u <username> --password --single-transaction <database_name> > <database_name>-backup-`date -I`.sql
Next, log out and in a local bash prompt, use scp
to pull the file to your local machine (current directory):
scp -P <port_number> <username>@<server_host>:<remote_file_path .
(Note: ssh uses a lowercase -p
to specify a port, but scp uses an uppercase -P
)