ssh+tar (tar cvf - . | ssh root@128.224.162.56 "cd /folk/tmp2/;tar xvfp -;echo "done"")

發現有資料復原不全, 但很多檔案又被異動過, 如果把舊資料倒回來, 又會覆蓋到新資料.


可以用find + tar來解決這問題

  1. 先備份已異動的檔案: 將在30天內有異動的"檔案"備份起來
    # find . -type f -mtime -30 | xargs tar zcvpf backup.tar.gz
  2. 將舊資料全部倒回, 再把已異動的backup.tar.gz解開覆蓋回去

联合使用ssh, tar和find复制特定文件

参考文献: http://www.computing.net/answers/unix/tar-find-ssh/6251.html

一个数据库的全文和元数据都放在一起,数据量接近200GB,用于处理元数据的服务器没有这么多空间,所以只想复制特定元数据文件。元数据文件可以通过find命令筛选出来,同时结合使用ssh和tar来远程复制文件。过程如下:

[root@xenhost2 2007]# pwd
/bkup02/ieee/fulltext/2007
[root@xenhost2 2007]# find ./ -name xml.zip
[root@xenhost2 2007]# cd
[root@xenhost2 ~]# (cd /bkup02/ieee/fulltext/2007; tar cf - $(find . -name xml.zip) ) | ssh user@xxx.xxx.xxx.xxx"tar -C /opt/backup/ieee/2007 -xf -"
user@xxx.xxx.xxx.xxx's password:

复制过去的文件保持了原来的目录结构,并且只包含特定的元数据文件,完全符合原始需求。
2006年的文件稍微有些不同:
[root@xenhost2 ~]# (cd /bkup02/ieee/fulltext/2006; tar cf - $(find . -name *.txt | grep -v pdf_data) ) | ssh user@xxx.xxx.xxx.xxx "tar -C /opt/backup/ieee/2006 -xf -"
user@xxx.xxx.xxx.xxx's password:

 

 

 

Howto: Use tar command through network over ssh session

Q. How do I use tar command over secure ssh session?

A. The GNU version of the tar archiving utility (and other old version of tar) can be use through network over ssh session. Do not use telnet command, it is insecure. You can use Unix/Linux pipes to create actives. Following command backups /wwwdata directory to dumpserver.nixcraft.in (IP 192.168.1.201) host over ssh session.

The default first SCSI tape drive under Linux is /dev/st0. You can read more about tape drives naming convention used under Linux here.

# tar zcvf - /wwwdata | ssh root@dumpserver.nixcraft.in "cat > /backup/wwwdata.tar.gz"OR# tar zcvf - /wwwdata | ssh root@192.168.1.201 "cat > /backup/wwwdata.tar.gz"

Output:

tar: Removing leading `/' from member names
/wwwdata/
/wwwdata/n/nixcraft.in/
/wwwdata/c/cyberciti.biz/
....
..
...
Password:

You can also use dd command for clarity purpose:# tar cvzf - /wwwdata | ssh ssh root@192.168.1.201 "dd of=/backup/wwwdata.tar.gz"It is also possible to dump backup to remote tape device:# tar cvzf - /wwwdata | ssh ssh root@192.168.1.201 "cat > /dev/nst0"OR you can use mt to rewind tape and then dump it using cat command:# tar cvzf - /wwwdata | ssh ssh root@192.168.1.201 $(mt -f /dev/nst0 rewind; cat > /dev/nst0)$You can restore tar backup over ssh session: # cd /
# ssh root@192.168.1.201 "cat /backup/wwwdata.tar.gz" | tar zxvf -
If you wish to use above command in cron job or scripts then consider
SSH keys to get rid of the passwords.

 

 

 

 

联合使用ssh和tar实现备份
2008-10-20 03:36

前面介绍过使用tar执行目录复制,以及使用tar和ssh实现远程复制的方法。今天为了执行备份,在网上找了如下一篇文章,介绍联合使用ssh和tar实现备份。原文是繁体的,为了阅读方便,将它转换为简体。
利用 ssh + tar 作备份
以前看网络上某篇文章時,节录下來的,出处已经不可考了.它是利用 ssh + tar 來作备份,不仅安全,也兼顾了部分的效率.

$target 表示目的机器,指远端机器
$backup_server 表示备份机器,同样也是指远端机器
$save 则是指备份目录

要求远端备份并拉回 local
ssh $target tar -cf - / --exclude /mnt | bzip2 -9 | cat > $target.tar.bz2

解开本地备份并回存到远端去
bunzip2 -dc $target.tar.bz2 | ssh $target "cd /;tar -pxkf -"

备份 local 资料,丟到远端去压缩并存档
tar cf - / --exclude xxx | ssh $backup_server "bzip2 -9 > $save/test.tar.bz2"

把远端资料拉回 local,作解压缩动作
ssh $backup_server "cat $save/test.tar.bz2" | bunzip2 | tar -xpkf -

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值