Linux MySQL从没有shell访问的远程转储到tar.gz

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4812578/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 02:39:10  来源:igfitidea点击:

MySQL Dump to tar.gz from remote without shell access

linuxshellmysqldumppipetar

提问by recluze

I'm trying to get a dump from MySQL to my local client. This is what I currently have:

我正在尝试从 MySQL 转储到我的本地客户端。这是我目前拥有的:

mysqldump -u $MyUSER -h $MyHOST -p$MyPASS $db | gunzip -9 > $FILE

mysqldump -u $MyUSER -h $MyHOST -p$MyPASS $db | gunzip -9 > $FILE

What I want though is .tar.gz instead of a gunzip archive. I have shell access on local client but not on the server. So, I can't do a remote tar and copy it here. So, is there a way of piping the gzip to a tar.gz. (Currently, the .gz does not get recognized as a tar archive.)

我想要的是 .tar.gz 而不是 gunzip 存档。我在本地客户端上有 shell 访问权限,但在服务器上没有。所以,我不能做一个远程 tar 并将它复制到这里。那么,有没有办法将 gzip 传输到 tar.gz。(目前,.gz 不会被识别为 tar 存档。)

Thanks.

谢谢。

采纳答案by Nylon Smile

If you are issuing the above command in client side, your compression is done in client side. mysqldump connects the remote server and downloads the data without any compression.

如果您在客户端发出上述命令,则压缩是在客户端完成的。mysqldump 连接远程服务器并下载没有任何压缩的数据。

mysqldump -u $MyUSER -h $MyHOST -p$MyPASS $db > filename
tar cfz filename.tar.gz filename
rm filename

Probably some unix gurus will have a one liner to do it.

可能一些 Unix 大师会有一个单行代码来做到这一点。

回答by Ignacio Vazquez-Abrams

No. The files (yes, plural, since tar is usually used for more than one file) are first placed in a tar archive, and thenthat is compressed. If you are trying to use the tarcommand line tool then you will need to save the result in a temporary file and then tar that.

不。文件(是的,复数,因为 tar 通常用于多个文件)首先放置在 tar 存档中,然后进行压缩。如果您尝试使用tar命令行工具,那么您需要将结果保存在一个临时文件中,然后对其进行 tar。

Personally though, I'd rather hit the other side with a cluebat.

不过就我个人而言,我宁愿用一个线索棒击中另一边。

回答by xelco52

mysqldump -u $MyUSER -h $MyHOST -p$MyPASS $db | tar -zcvf $FILE -

mysqldump -u $MyUSER -h $MyHOST -p$MyPASS $db | tar -zcvf $FILE -

Where $FILE is your filename.tar.gz

$FILE 是你的文件名.tar.gz

回答by Mihai

Archived backup and renamed by time and date:

归档备份并按时间和日期重命名:

/usr/bin/mysqldump -u $MyUSER -h $MyHOST -p$MyPASS $db | gzip -c > /home/backup_`/bin/date +"\%Y-\%m-\%d_\%H:\%M"`.gz