
正式な方法は何ですか?
scp
ファイルをリモートの場所に- 転送中のファイルを圧縮します(
tar
個々のファイル、フォルダ全体、7za
または他のより効率的な圧縮)。 - 中間ファイルを保存せずに上記の操作を実行します。
私は次のようなシェルパイプに精通しています。
tar cf - MyBackups | 7za a -si -mx=9 -ms=on MyBackups.tar.7z
基本的に:
- フォルダ全体を1つにマージ
tar
- データをコンプレッサー
stdout
に渡すstdin
- 適用する怒る圧縮
ssh
リンクを介してこれを行い、ファイルをリモートファイルシステムに保存する最善の方法は何ですか?
sshfs
むしろインストールしない方が良いでしょう。
これはうまくいきません:
scp <(tar cvf - MyBackups | 7za a -si -mx=9 -so) localhost:/tmp/tmp.tar.7z
なぜなら:
/dev/fd/63: not a regular file
答え1
必要なことを行う方法はいくつかあります。最も簡単な方法はpipeを使用することです。
tar zcvf - MyBackups | ssh user@server "cat > /path/to/backup/foo.tgz"
ここで圧縮はtar
任意の呼び出しgzip
(フラグ)によってz
処理されます。compress
(Z
)とbzip
()を使用することもできますj
。の場合は、7z
次のようにします。
tar cf - MyBackups | 7za a -si -mx=9 -ms=on MyBackups.tar.7z |
ssh user@server "cat > /path/to/backup/foo.7z"
これ最高しかし、方法はrsync
。
Rsync is a fast and extraordinarily versatile file copying tool. It can copy
locally, to/from another host over any remote shell, or to/from a remote rsync dae‐
mon. It offers a large number of options that control every aspect of its behavior
and permit very flexible specification of the set of files to be copied. It is
famous for its delta-transfer algorithm, which reduces the amount of data sent over
the network by sending only the differences between the source files and the exist‐
ing files in the destination. Rsync is widely used for backups and mirroring and
as an improved copy command for everyday use.
rsync
持つ方法選択肢が多すぎます。確かに読んでみる価値がありますが、一目で怖いです。この場合、あなたの懸念は次のとおりです。
-z, --compress compress file data during the transfer
--compress-level=NUM explicitly set compression level
-z, --compress
With this option, rsync compresses the file data as it is sent to the desti‐
nation machine, which reduces the amount of data being transmitted --
something that is useful over a slow connection.
Note that this option typically achieves better compression ratios than can
be achieved by using a compressing remote shell or a compressing transport
because it takes advantage of the implicit information in the matching data
blocks that are not explicitly sent over the connection.
したがって、あなたの場合は、次のようなことをしたいと思います。
rsync -z MyBackups user@server:/path/to/backup/
ファイルは転送中に圧縮され、宛先に到達すると解凍されます。
より多くの選択:
scp
データ自体を圧縮できます-C Compression enable. Passes the -C flag to ssh(1) to enable compression. $ scp -C source user@server:/path/to/backup
rsync
たぶんあなたが親切になる方法があるかもしれませんが7za
、そうすることは役に立ちません。この方法の利点rsync
は、ローカルファイルとリモートファイルの間で変更されたビットのみをコピーすることです。ただし、ローカルの小さな変更によって圧縮ファイルが非常に異なる可能性があるため、使用する必要はありませんrsync
。それは仕事を複雑にし、役に立たない。ssh
上図のように直接使用してください。もしあなたなら本物これを行うには、サブシェルを引数として渡してみてくださいrsync
。私のシステムでは、7za
圧縮データを端末に書き込めないため使用できません。実装が異なる場合があります。次のことを試してください(これは私には合わない):rsync $(tar cf - MyBackups | 7za a -an -txz -si -so) \ user@server:/path/to/backup
もう一つの点は
7z
Linuxのバックアップには使用しないでください。。マニュアルページには次のように表示されます7z
。次の理由から、Linux/Unix バックアップに 7-zip 形式を使用しないでください。
- 7-zipはファイルの所有者/グループを保存しません。
答え2
私の考えでは、この命令はうまくいくと思います。
ssh user@host "cd /path/to/data/;tar zc directory_name" | tar zx
まず、ターゲットホストでこのコマンドを実行する必要があります。そして説明が必要な詳細は次のとおりです。
- ssh user@host はホストへの接続を開き、ホストからデータを転送します。
- cd /path/to/data は、必要なデータが格納されているディレクトリに入ります。
- tar zc *は圧縮を開始し、それをSTDOUTに入れます。
- パイプ(|)は、ソースのSTDOUTを「tar zx」を実行しているターゲットのSTDINにパイプし、ソースのデータストリームを連続的に解凍します。
ご覧のとおり、このコマンドはすぐに帯域幅を圧縮して保存します。より良い結果を得るために別の圧縮を使用することもできますが、圧縮と解凍にはCPUサイクルが必要であることに注意してください。
答え3
小さな改善dkbhadeshiyaの答え:これを行う必要はなく、cd dir
作業ディレクトリを指定するだけですtar
。
ssh user@host "tar -C /path/to/data/ -zc directory_name" | tar zx
同じ方法でディレクトリをアップロードすることもできます。
tar zc directory_name/ | ssh user@host "tar zx -C /new/path/to/data/"