Using tar and ssh to efficiently copy files preserving permissions

https://meinit.nl/using-tar-and-ssh-to-efficiently-copy-files-preserving-permissions


Have you had situations where disk-space is sparse, so making full tars (although compressed) is impossible? Here is an ssh trick that could help you copy over files without using too much diskspace.

This trick will tar a directory from a computer, but the file that it would normally create, is standard out, so it is redirected back to the script on the computer you are working on. The computer you are working on extracts the information directly, so there is no location where (redundant) files are stored.

ssh user@machine-where-precious-data-is "tar czpf - /some/important/data" | tar xzpf - -C /new/root/directory

You are now directly copying data from the "machine-where-precious-data-is" to the machine you are working on, using the benefits of tar (preserving permissions, links, etc) but not being hindered by the difficulties of tar. (making these possibly large files and so on.)
I used this trick to copy users directories from one machine to the other.

An alternative command, reverse and not crossing filesystem boundries:

tar cpf - /some/important/data | ssh user@destination-machine "tar xpf - -C /some/directory/"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值