以前有个别服务器备份是用tar+gzip打包压缩后再ftp传到异地备份,现改成通过tar+ssh的方式,可以直接备份到异地,减少在本地生成备份包,及通过内部网络传输来降低tar+gzip打包时对磁盘的IO压力。
1,tar调用gzip打包压缩到远程服务器:
有两种方式,一是通过dd of,一是cat >,测试是dd of快一些,不过是跟当时服务器的负载有关系
[root@local ~]# time tar -czf – -T /mail/backup/DIR.txt |ssh [email protected] “dd of=/mail/test.tar.gz” tar: Removing leading `/’ from member names 2696500+0 records in 2696500+0 records out real 6m51.373s user 3m8.539s sys 0m14.306s [root@local ~]# time tar -czf – -T /mail/backup/DIR.txt |ssh [email protected] “cat > /mail/2.tar.gz” tar: Removing leading `/’ from member names real 9m31.059s user 3m10.916s sys 0m14.924s [root@target test]# ll test.tar.gz 2.tar.gz -rw-r–r– 1 root root 1378488320 Apr 17 11:47 2.tar.gz -rw-r–r– 1 root root 1380608000 Apr 16 18:06 test.tar.gz
2,也可以本地服务器进行打包,再到异地服务器进行压缩:
[root@local ~]# time tar -cf – -T /mail/backup/DIR.txt |ssh [email protected] “gzip -1 > /mail/3.tar.gz” tar: Removing leading `/’ from member names real 7m18.473s user 0m29.029s sys 0m12.023s
3,把远端服务器的压缩包直接解压到本地:
ssh [email protected] “cat /mail/test.tar.gz” | tar zxvf -
4,本地打包压缩传输到异地解压:
tar -czf – /mail/backup/DIR.txt|ssh [email protected] “cd /mail;tar -zxf -”