H
H
HirasawaYui2019-12-17 16:39:20
IT education
HirasawaYui, 2019-12-17 16:39:20

How to output mysqldump result to remote server via ssh?

I connect via ssh to the server, sending commands to it via plink (writing them into a .bat file).
My script looks like this:

C:/mypath/plink.exe -batch ^
[email protected] -pw mypassword ^
"mysqldump -u database_user -pdbpass database_name > mysqlBackup/dbdump.sql"
pause

In this case, mysqldump is executed on the remote machine, but the result is written to the mysqlBackup/dbdump.sql file on the local machine, which naturally takes a lot of time. How to specify in a command that the result should be written to a file in the same place, on a remote machine?
I would also like to run it in gzip, that is:
mysqldump -u database_user -pdbpass database_name | gzip > mysqlBackup/dbdump.sql.gz

and then actually upload the resulting backup to the local machine:
scp C:/mypath/ [email protected]:~/mysqlBackup/dbdump.sql.gz

Answer the question

In order to leave comments, you need to log in

5 answer(s)
L
longclaps, 2019-02-03
@longclaps

Denis why?

M
Mikhail Kargin, 2019-02-04
@WaterSeer

Try watching Alexander Shevchuk from ITVDN.

H
HirasawaYui, 2019-12-17
@HirasawaYui

I found what was the problem, it turns out that escape characters in my script - "^", in an incomprehensible way to me influenced the script, and specifically - "^" immediately before the quotes, which contain the transmitted command to be executed on a remote machine, i.e. I rewrote the whole command:

C:/mypath/plink.exe -batch ^
[email protected] -pw mypassword ^
"mysqldump -u database_user -pdbpass database_name > mysqlBackup/dbdump.sql"

in one line:
And everything worked as it should, i.e. output goes to the mysqlBackup/dbdump.sql file on the server. Marvelous. I would be grateful if someone could explain this logic.

A
Alexander Chernykh, 2019-12-17
@sashkets

we connect via ssh to a remote host
, we do what we need in the console
from the local computer, we execute sftp on the host (you can use winscp)
we take the result

I
iddqda, 2019-12-17
@iddqda

I don’t know about Windows, but in Linux it would work like this

mysqldump -u database_user -pdbpass database_name | \
gzip -c | ssh [email protected] "cat > mysqlBackup/dbdump.sql.gz"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question