备份的目标文件夹存放备份的路径
[root@V71 backup]# ls /nfs_test/
1.txt host-manager.2019-05-22.log localhost.2019-05-23.log manager.2019-05-22.log
catalina.2019-05-22.log host-manager.2019-05-23.log localhost_access_log.2019-05-22.txt manager.2019-05-23.log
catalina.2019-05-23.log localhost.2019-05-22.log localhost_access_log.2019-05-23.txt
[root@V71 backup]# pwd
/backup
第一次执行全量备份
[root@V71 backup]# tar -g /backup/snapshot -zcvf /backup/full.tar.gz /nfs_test
tar: /nfs_test:目录是新的
tar: 从成员名中删除开头的“/”
/nfs_test/
/nfs_test/1.txt
/nfs_test/catalina.2019-05-22.log
/nfs_test/catalina.2019-05-23.log
/nfs_test/host-manager.2019-05-22.log
/nfs_test/host-manager.2019-05-23.log
/nfs_test/localhost.2019-05-22.log
/nfs_test/localhost.2019-05-23.log
/nfs_test/localhost_access_log.2019-05-22.txt
/nfs_test/localhost_access_log.2019-05-23.txt
/nfs_test/manager.2019-05-22.log
/nfs_test/manager.2019-05-23.log
注意:此/backup/snapshot为快照文件,如果不删除此文件,将来用-g指定此文件,再备份相同的目录的话,都将是增量备份
备份出来的内容如下:
[root@V71 backup]# tar -ztf full.tar.gz
nfs_test/
nfs_test/1.txt
nfs_test/catalina.2019-05-22.log
nfs_test/catalina.2019-05-23.log
nfs_test/host-manager.2019-05-22.log
nfs_test/host-manager.2019-05-23.log
nfs_test/localhost.2019-05-22.log
nfs_test/localhost.2019-05-23.log
nfs_test/localhost_access_log.2019-05-22.txt
nfs_test/localhost_access_log.2019-05-23.txt
nfs_test/manager.2019-05-22.log
nfs_test/manager.2019-05-23.log
向备份的目标文件夹写入内容1
[root@V71 nfs3]# cd /nfs_test/
[root@V71 nfs_test]# touch admin.txt
[root@V71 nfs_test]# echo "testing" >> admin.txt
[root@V71 nfs_test]# cat admin.txt
testing
此时执行备份,因为/backup/snapshot为先前的快照,/nfs_test前面也有备份,这样本次备份即为增量备份
增量备份1
[root@V71 backup]# tar -g /backup/snapshot -zcvf /backup/in1.tar.gz /nfs_test
tar: 从成员名中删除开头的“/”
/nfs_test/
/nfs_test/admin.txt
查看备份出来的内容
[root@V71 ~]# tar ztf /backup/in1.tar.gz
nfs_test/
nfs_test/admin.txt
向备份的目标文件夹写入内容2
[root@V71 backup]# touch /nfs_test/admin2.txt
[root@V71 backup]# echo "testings" >> /nfs_test/admin2.txt
增量备份2
[root@V71 backup]# tar -g snapshot -zcvf in2.tar.gz /nfs_test
tar: 从成员名中删除开头的“/”
/nfs_test/
/nfs_test/admin2.txt
查看备份出来的内容
[root@V71 ~]# tar ztf /backup/in2.tar.gz
nfs_test/
nfs_test/admin2.txt
删除数据并还原
[root@V71 backup]# rm -rf /nfs_test/*.*
还原全量备份
[root@V71 backup]# tar -zxvf full.tar.gz --strip-components 1 -C /nfs_test
#--strip-components 1表示去除文件名前1层路径 ,也就是把备份归档的nfs_test这一层去掉,直接把文件弄进-C指定的/nfs_test
nfs_test/1.txt
nfs_test/catalina.2019-05-22.log
nfs_test/catalina.2019-05-23.log
nfs_test/host-manager.2019-05-22.log
nfs_test/host-manager.2019-05-23.log
nfs_test/localhost.2019-05-22.log
nfs_test/localhost.2019-05-23.log
nfs_test/localhost_access_log.2019-05-22.txt
nfs_test/localhost_access_log.2019-05-23.txt
nfs_test/manager.2019-05-22.log
nfs_test/manager.2019-05-23.log
[root@V71 backup]# ls /nfs_test/
1.txt host-manager.2019-05-22.log localhost.2019-05-23.log manager.2019-05-22.log
catalina.2019-05-22.log host-manager.2019-05-23.log localhost_access_log.2019-05-22.txt manager.2019-05-23.log
catalina.2019-05-23.log localhost.2019-05-22.log localhost_access_log.2019-05-23.txt
还原增量备份1
[root@V71 backup]# tar -zxvf in1.tar.gz --strip-components 1 -C /nfs_test
nfs_test/admin.txt
还原增量备份2
[root@V71 backup]# tar -zxvf in2.tar.gz --strip-components 1 -C /nfs_test
nfs_test/admin2.txt
验证数据
[root@V71 backup]# ls /nfs_test/
1.txt catalina.2019-05-22.log host-manager.2019-05-23.log localhost_access_log.2019-05-22.txt manager.2019-05-23.log
admin2.txt catalina.2019-05-23.log localhost.2019-05-22.log localhost_access_log.2019-05-23.txt
admin.txt host-manager.2019-05-22.log localhost.2019-05-23.log manager.2019-05-22.log
注意,全量和所有的增量备份文件名一定不能相同