焦油通过SSH:设定目标文件名和位置,并覆盖现有 [英] tar over ssh: Set destination file name and location, and overwrite existing

查看:135
本文介绍了焦油通过SSH:设定目标文件名和位置,并覆盖现有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要解释这个问题的最简单方法是显示code的以下行,我有一个bash脚本。

The easiest way to explain this question is show the following line of code which I have in a bash script.

tar -cJf - ./my_folder | ssh user@example 'tar -xJf - && rm -r ./path-to-my_folder/my_folder && mv ./my_folder ./path-to-my_folder'

我不完全了解它是如何工作。 (这是什么' - '在这方面的意思吗?),但是,这是它做什么:

I don't fully understand how it works. (What does '-' mean in this context?) But this is what it does:


  • 在内存中创建一个COM pressed tar归档和管通过SSH某种程度上推动焦油数据

  • Creates a compressed tar archive in memory and the pipe somehow pushes the tar data over ssh

tar包出现在用户的根文件夹,它是提取

The tar archive appears in users root folder, it is extracted

ssh命令继续执行在东西之间...,在服务器端的删除旧文件夹使用 RM ,并从用户的根目录移动提取的文件夹替换

The ssh command continues executing the stuff in the between ' ... ', the old folder on the server side is removed using rm and replaced by moving the extracted folder from the user's root directory

很明显,这是一个做事的相当长的路要走。如果tar归档提取到正确的位置,使 RM MV 命令不会是它会更好必要。可以这样做?

It is obvious that this is a rather long way of doing things. It would be better if the tar archive was extracted to the correct location so that the rm and mv commands would not be necessary. Can this be done?

注:我不能使用的rsync

推荐答案

试试这个:

tar -cJf - ./my_folder | ssh user@example 'tar -xJf - -C path-to-my_folder'

- 符号的意思的 STDOUT 的。但在现代焦油实施的 STDOUT 默认的输出,所以 -f - 可以省略了:

The - sign mean STDOUT. But in modern tar implementation, STDOUT is default output, so -f - could be omited:

tar -cJ my_folder | ssh user@example 'tar -xJC path-to-my_folder'

-J 开关意味着 XZ COM pression,至极可能是杀鸡用牛刀小配置(如树莓丕,Android和许多嵌入系统),所以你可以使用 -z 开关的gzip 获得更好的性能COM pression:

The -J switch mean xz compression, wich could be overkill on small configuration (like raspberry-pi, android and many embed systems), so you could obtain better performances by using -z switch for gzip compression:

tar -zc my_folder | ssh user@example 'tar -zxC path-to-my_folder'

这篇关于焦油通过SSH:设定目标文件名和位置,并覆盖现有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆