当前位置:   article > 正文

压缩和归档操作_zip_deflated

zip_deflated

一、归档备份概述

1.文件归档

将许多零散的文件打包,并记录好各自的位置

−并不压缩其存储空间

−主要起到整理、备案的作用

2.文件压缩

将单个文件按照某种算法重新编码存放

−只针对单个文件

−主要起到降低文件大小、节省磁盘空间的作用

3.归档压缩包

4.归档压缩格式

二、zip压缩工具

1.制作.zip压缩包

zip 备份操作

−用法:zip [-r] 压缩包名被压缩的文档...

先安装命令zip

  1. [root@hadoop ~]# yum install zip
  2. Setting up Install Process
  3. Resolving Dependencies
  4. --> Running transaction check
  5. ---> Package zip.x86_64 0:3.0-1.el6_7.1 will be installed
  6. --> Finished Dependency Resolution
  7. Dependencies Resolved
  8. ========================================================================================================================
  9. Package Arch Version Repository Size
  10. ========================================================================================================================
  11. Installing:
  12. zip x86_64 3.0-1.el6_7.1 base 259 k
  13. Transaction Summary
  14. ========================================================================================================================
  15. Install 1 Package(s)
  16. Total download size: 259 k
  17. Installed size: 804 k
  18. Is this ok [y/N]: y
  19. Downloading Packages:
  20. zip-3.0-1.el6_7.1.x86_64.rpm | 259 kB 00:00
  21. Running rpm_check_debug
  22. Running Transaction Test
  23. Transaction Test Succeeded
  24. Running Transaction
  25. Installing : zip-3.0-1.el6_7.1.x86_64 1/1
  26. Verifying : zip-3.0-1.el6_7.1.x86_64 1/1
  27. Installed:
  28. zip.x86_64 0:3.0-1.el6_7.1
  29. Complete!
  1. [root@hadoop ~]# ls -lh /etc >ziptest.txt //建测试文件
  2. [root@hadoop ~]# zip ziptest.zip ziptest.txt //压缩
  3. adding: ziptest.txt (deflated 79%)
  4. [root@hadoop ~]# ls -lh ziptest.*
  5. -rw-r--r--. 1 root root 8.1K Apr 29 14:38 ziptest.txt
  6. -rw-r--r--. 1 root root 1.9K Apr 29 14:42 ziptest.zip

2.zip备份应用实例

任务目标

−将目录/etc/init.d和文件install.log 备份为/opt/mybak.zip

  1. [root@hadoop ~]# zip -r /opt/mybak.zip /etc/init.d/ install.log
  2. adding: etc/init.d/ (stored 0%)
  3. adding: etc/init.d/rsyslog (deflated 56%)
  4. adding: etc/init.d/rdisc (deflated 55%)
  5. adding: etc/init.d/ip6tables (deflated 72%)
  6. adding: etc/init.d/atd (deflated 62%)
  7. adding: etc/init.d/lvm2-monitor (deflated 52%)
  8. adding: etc/init.d/lvm2-lvmetad (deflated 50%)
  9. adding: etc/init.d/blk-availability (deflated 43%)
  10. adding: etc/init.d/ntpd (deflated 57%)
  11. adding: etc/init.d/functions (deflated 67%)
  12. adding: etc/init.d/sshd (deflated 66%)
  13. adding: etc/init.d/restorecond (deflated 54%)
  14. adding: etc/init.d/udev-post (deflated 56%)
  15. adding: etc/init.d/mysqld (deflated 63%)
  16. adding: etc/init.d/crond (deflated 64%)
  17. adding: etc/init.d/auditd (deflated 60%)
  18. adding: etc/init.d/iptables (deflated 71%)
  19. adding: etc/init.d/halt (deflated 57%)
  20. adding: etc/init.d/single (deflated 41%)
  21. adding: etc/init.d/netconsole (deflated 56%)
  22. adding: etc/init.d/saslauthd (deflated 57%)
  23. adding: etc/init.d/network (deflated 65%)
  24. adding: etc/init.d/sandbox (deflated 56%)
  25. adding: etc/init.d/netfs (deflated 67%)
  26. adding: etc/init.d/ntpdate (deflated 51%)
  27. adding: etc/init.d/postfix (deflated 62%)
  28. adding: etc/init.d/killall (deflated 45%)
  29. adding: install.log (deflated 73%)

3.释放.zip压缩包

unzip 解压操作−用法:unzip [-d 目标文件夹] .zip压缩包

安装命令

  1. [root@hadoop ~]# yum install unzip
  2. Setting up Install Process
  3. Resolving Dependencies
  4. --> Running transaction check
  5. ---> Package unzip.x86_64 0:6.0-5.el6 will be installed
  6. --> Finished Dependency Resolution
  7. Dependencies Resolved
  8. ========================================================================================================================
  9. Package Arch Version Repository Size
  10. ========================================================================================================================
  11. Installing:
  12. unzip x86_64 6.0-5.el6 base 152 k
  13. Transaction Summary
  14. ========================================================================================================================
  15. Install 1 Package(s)
  16. Total download size: 152 k
  17. Installed size: 324 k
  18. Is this ok [y/N]: y
  19. Downloading Packages:
  20. unzip-6.0-5.el6.x86_64.rpm | 152 kB 00:00
  21. Running rpm_check_debug
  22. Running Transaction Test
  23. Transaction Test Succeeded
  24. Running Transaction
  25. Installing : unzip-6.0-5.el6.x86_64 1/1
  26. Verifying : unzip-6.0-5.el6.x86_64 1/1
  27. Installed:
  28. unzip.x86_64 0:6.0-5.el6
  29. Complete!
  1. [root@hadoop ~]# unzip -d zdir/ ziptest.zip //释放到指定目录
  2. Archive: ziptest.zip
  3. inflating: zdir/ziptest.txt
  4. [root@hadoop ~]# ls zdir/
  5. ziptest.txt
  6. [root@hadoop ~]# cd /opt/
  7. [root@hadoop opt]# unzip /opt/mybak.zip //释放到当前目录
  8. Archive: /opt/mybak.zip
  9. creating: etc/init.d/
  10. inflating: etc/init.d/rsyslog
  11. inflating: etc/init.d/rdisc
  12. inflating: etc/init.d/ip6tables
  13. inflating: etc/init.d/atd

三、gzip/bzip2/xz压缩工具

1.制作.gz压缩包

gzip压缩操作

−用法:gzip[-9] 文件名...

-分别压缩每个文件,原始文件不保留

  1. [root@hadoop opt]# ls -lh /etc/ >gztest.txt //建测试文件
  2. [root@hadoop opt]# gzip gztest.txt //压缩
  3. [root@hadoop opt]# ls -lh gztest.txt*
  4. -rw-r--r--. 1 root root 1.8K Apr 29 14:51 gztest.txt.gz

2.释放.gz压缩包

gunzip解压操作

−用法1:gunzip.gz压缩包.. ..

−用法2:gzip-d .gz压缩包.. ..

−分别解压每个.gz包文件,原始文件不保留

  1. [root@hadoop opt]# gzip -d gztest.txt.gz //解压缩
  2. [root@hadoop opt]# ls -lh gztest.txt*
  3. -rw-r--r--. 1 root root 8.1K Apr 29 14:51 gztest.txt

3.bzip2与bunzip2

4.xz与unxz

四、tar归档及压缩

1.制作.tar归档包

tar 制作备份

−用法:tar -cf.tar归档包名被归档的文件.. ..

−逐一复制并归档,原始文件保留

−选项含义:-c 创建、-v 细节、-P 保留根路径、-f 归档

  1. [root@hadoop opt]# tar -cf slbak.tar /etc/selinux //新建归档
  2. tar: Removing leading `/' from member names
  3. [root@hadoop opt]# tar -tf slbak.tar //查看归档内容
  4. etc/selinux/
  5. etc/selinux/restorecond_user.conf
  6. etc/selinux/config

2.释放.tar归档包

tar 释放备份

−用法:tar -xf.tar归档包[-C 目标目录]

−解包并逐一提取,原始文件保留

−选项含义:-x 释放、-C 存放的目标位置

  1. [root@hadoop opt]# tar -xf slbak.tar -C /opt/ //释放归档到指定目录
  2. [root@hadoop opt]# ls /opt/etc/selinux/
  3. config restorecond.conf restorecond_user.conf semanage.conf targeted

3.归档+压缩的整合

 

4.备份应用实例

任务目标

−将/etc和/srv目录备份为/opt/etcsrv.tar.gz 文件

−保留原始文档的根路径(-P)、权限等属性(-p)

  1. [root@hadoop opt]# tar -zcpPf /opt/etcsrv.tar.gz /etc/ /srv/
  2. [root@hadoop opt]# ls -lh /opt/etcsrv.tar.gz
  3. -rw-r--r--. 1 root root 8.1M Apr 29 15:02 /opt/etcsrv.tar.gz
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/170390
推荐阅读
相关标签
  

闽ICP备14008679号