Linux 在shell脚本中使用ssh连接的mysqldump
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9821111/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
mysqldump with ssh connection in shell script
提问by 9edge
I'm using a shell script that opens a ssh connection and creates an sqldump.
我正在使用打开 ssh 连接并创建 sqldump 的 shell 脚本。
But, when I use mysqldump
in the shell script it gives me the error:
"No such file or directory"
但是,当我mysqldump
在 shell 脚本中使用时,它给了我错误:“没有这样的文件或目录”
This is the line I use:
这是我使用的线路:
ssh user@host mysqldump -uusername -hlocalhost -ppassword --all-databases > /home/user/sqlfile.sql
The mysqldump
works when i use it in an opened ssh connection or at the server in the commandline.
mysqldump
当我在打开的 ssh 连接中或在命令行中的服务器上使用它时,工作正常。
So my question is why do I get the error and why can't I run the mysqldump command in a shell script?
所以我的问题是为什么我会收到错误,为什么我不能在 shell 脚本中运行 mysqldump 命令?
采纳答案by gogators
You need to escape the > symbol. Try this:
您需要转义 > 符号。尝试这个:
ssh user@host mysqldump -uusername -hlocalhost -ppassword --all-databases \> /home/user/sqlfile.sql
回答by eggmatters
You can also enclose your ssh remote commands in quotes. e.g.
您还可以将 ssh 远程命令括在引号中。例如
ssh user@host "mysqldump -uusername -hlocalhost -ppassword --all-databases > /home/user/sqlfile.sql"
That way, if you want to scp the dump to your local folder all in one, you can:
这样,如果您想将转储一并复制到本地文件夹,您可以:
ssh user@host "mysqldump -uusername -hlocalhost -ppassword --all-databases" > /home/user/sqlfile.sql