A-A+

Network File Copy using SSH

2009年03月02日 学习随笔 暂无评论 阅读 1 次

http://ultra.ap.krakow.pl/~bar/DOC/ssh_backup.html

Network File Copy using SSH
Updated February 20, 2003
Created April 23, 2001
Please note that &&, ||, and -, are documented at the bottom of this page.

PUSH:
* tar cvf - . | gzip -c -1 | ssh user@host cat ">" remotefile.gz
* ssh target_address cat " remotefile
* ssh target_address cat " remotefile
* cat localfile | ssh target_address cat ">" remotefile
* cat localfile | ssh target_address cat - ">" remotefile
* dd if=localfile | ssh target_address dd of=remotefile
* ssh target_address cat remotefile.tar )"
* ( cd SOURCEDIR && tar czvf - . ) | ssh target_address "(cd DESTDIR && cat - > remotefile.tgz )"
* ( cd SOURCEDIR && tar cvf - . | gzip -1 -) | ssh target_address "(cd DESTDIR && cat - > remotefile.tgz )"
* ssh target_address "( nc -l -p 9210 > remotefile & )" && cat source-file | gzip -1 - | nc target_address 9210
* cat localfile | gzip -1 - | ssh target_address cat ">" remotefile.gz

PULL:
ssh target_address cat remotefile > localfile
ssh target_address dd if=remotefile | dd of=localfile
ssh target_address cat "< " remotefile >localfile
ssh target_address cat "< " remotefile.gz | gunzip >localfile

COMPARE:
###This one uses CPU cycles on the remote server to compare the files:
ssh target_address cat remotefile | diff - localfile
cat localfile | ssh target_address diff - remotefile
###This one uses CPU cycles on the local server to compare the files:
ssh target_address cat get file.gif "| xv -"
* ftp> get README "| more"

FTP PUSH:
* ftp> put "| tar cvf - ." myfile.tar
* ftp> put "| tar cvf - . | gzip " myfile.tar.gz

FTP PULL:
* ftp> get myfile.tar "| tar xvf -"

Pipes and Redirects:
* zcat Fig.ps.Z | gv -
* gunzip -c Fig.ps.gz | gv -
* tar xvf mydir.tar
* tar xvf - < mydir.tar
* cat mydir.tar | tar xvf -
* tar cvf mydir.tar .
* tar cvf - . > mydir.tar
* tar cf - . | (cd ~/newdir; tar xf -)
* gunzip -c foo.gz > bar
* cat foo.gz | gunzip > bar
* zcat foo.gz > bar
* gzip -c foo > bar.gz
* cat foo | gzip > bar.gz
* cat foo | gzip > bar.gz

SSH Keys
see http://www.cpqlinux.com/sshkeys.html
Explanation of &&, ||, and -
&& is shorthand for "if true then do"
|| is shorthand for "if false then do"
These can be used separately or together as needed. The following examples will attempt to change directory to "/tmp/mydir"; you will get different results based on whether "/tmp/mydir" exists or not.
cd /tmp/mydir && echo was able to change directory
cd /tmp/mydir || echo was not able to change directory
cd /tmp/mydir && echo was able to change directory || echo was not able to change to directory
cd /tmp/mydir && echo success || echo failure
cd /tmp/mydir && echo success || { echo failure; exit; }

The dash "-" is used to reference either standard input or standard output. The context in which the dash is used is what determines whether it references standard input or standard output.
Homepage: http://www.cpqlinux.com
Site Map: http://www.cpqlinux.com/sitemap-date.html

 

再如,为了ufsdump到一

再如,为了ufsdump到一个远程磁带机,可以使用如下命令:
/usr/sbin/ufsdump 0cfu - / | ssh chenuw@166.111.120.64 "cat > /dev/rmt/0n"

再如,为了还原数据

再如,为了还原数据,可以使用如下命令:
ssh chenuw@166.111.120.57 "cat /data4/ei_bkup/eidb2_20080216/ora2.tar.gz" |
/usr/local/bin/tar zxvf -

再如,为了备份数据

再如,为了备份数据,可以使用如下命令:
/usr/local/bin/tar zcvf - /ora | ssh chenuw@166.111.120.57 "cat > /data4/ei_bkup/eidb2_20080216/ora.tar.gz"
/usr/local/bin/tar zcvf - /ora2 | ssh chenuw@166.111.120.57 "cat > /data4/ei_bkup/eidb2_20080216/ora2.tar.gz"
/usr/local/bin/tar zcvf - /ora3 | ssh chenuw@166.111.120.57 "cat > /data4/ei_bkup/eidb2_20080216/ora3.tar.gz"

例如,为了复制数据

例如,为了复制数据,可以采用如下命令:
(cd /data1/soft/incoming/ && tar czf - . ) | ssh 166.111.120.155 "(cd /bkup01/soft/incoming && tar xzf -)"

给我留言

Copyright © 浩然东方 保留所有权利.   Theme  Ality 07032740

用户登录