tar备份与恢复

mac2022-06-30  22

tarball备份包

归档和压缩

归档的含义

将许多零散的文件整理为一个文件文件总的大小基本不变 压缩的含义按某种算法减小文件所占用空间的大小恢复是按对应的逆向算法解压

tar工具的常用选项

tar 集成备份工具

-c :创建归档-x :释放归档-f :指定归档文件名称-z、-j、-J:调用.gz、.bz2、.xz格式的工具进行处理-t :显示归档中的文件清单-C:指定释放路径

备份与恢复操作

制作tar备份包

使用 tar -c … 命令

tar -zcf 备份文件.tar.gz 被备份的文档…tar -jcf 备份文件.tar.bz2 被备份的文档…tar -Jcf 备份文件.tar.xz 被备份的文档… ]# du -sh /home/ 44K /home/ ]# tar -jcf /root/home.tar.bz2 /home ]# ls -lh /root/home.tar.bz2 -rw-r--r--. 1 root root 1.9K Nov 11 16:41 /root/home.tar.bz2

查看tar备份包内容

使用 tar -t … 命令

]# tar -tf /root/home.tar.bz2 home/ home/student/ home/student/.bash_logout

从tar备份包恢复文档

使用tar -xf … 命令

tar -xf 备份文件.tar.gz 【-C 目标文件夹】 ]# rm -rf /home ]# tar -xf /root/home.tar.bz2 ]# ls -ld /home/ drwxr-xr-x. 5 root root 45 Nov 11 16:09 /home/ ]# tar -xf /root/home.tar.bz2 -C /tmp/ tar:Removing leading `/‘ from member names ]# ls -ld /tmp/home/ drwxr-xr-x. 5 root root 45 Nov 11 16:09 /tmp/home/
最新回复(0)