(Linux学习笔记一:压缩)[20180209]

2018-02-10 13:08:24来源:cnblogs.com作者:请点..头像人点击

分享
学习笔记一:压缩2015年2月5日上午 10:23压缩命令压缩文件的扩展名大多是*.tar、*.tar.gz、*.tgz、*.gz、*.Z、*.bz2常见的压缩命令gzip与bzip2,其中bzip2压缩比gzip要好tar可以用来进行文件打包,并可支持gzip和bzip2的压缩压缩 tar -jvc -f  filename.tar.bz2 /directory查询 tar -jtv -f  filename.tar.bz2解压 tar -jxv -f filename.tar.bz2 -C /puorose/directoryDump 命令可备份文件系统或单一目录Dump 的备份若针对文件系统时,可进行0~9的level差异备份。其中level为0为完整备份restore命令可以还原被dump构建的备份文件要新建光盘刻录数据时,可通过mkisofs命令来构建可通过cdrecord来写入CD或DVD刻录机dd可备份完整的分区或磁盘,因为dd可读取硬盘的扇区表面数据cpio为相当优秀的备份命令,不过必须要搭配类似find命令来读入预备份文件测试演练gzip与bzip2压缩 tar打包使用gzip压缩格式并且排除log和bz压缩档[oracle@xitest01 schema]$  tar -zcv -f schema_tar_test.tar.gz --exclude=/u03/schema/*.log --exclude=/u03/schema/*.bz   /u03/schema使用bzip2压缩格式并且排除log和gz压缩档[oracle@xitest01 schema]$  tar -jcv -f schema_tar_test.tar.bz2 --exclude=/u03/schema/*.log --exclude=/u03/schema/*.gz   /u03/schema查看两者压缩比例[oracle@xitest01 schema]$ du -sh schema_tar_test.tar.*160K    schema_tar_test.tar.bz2260K    schema_tar_test.tar.gzdump备份文件系统模拟一个文件盘符[root@xitest01 u04]# dd if=/dev/zero of=/u04/loop_mount bs=1M count=10241024+0 records in1024+0 records out1073741824 bytes (1.1 GB) copied, 8.35942 seconds, 128 MB/s[root@xitest01 u04]#  mkfs.ext3 /u04/loop_mount[root@xitest01 u04]# mount -o loop  /u04/loop_mount /u04/mount_loop[root@xitest01 u04]# df -hFilesystem            Size  Used Avail Use% Mounted on/dev/sda2             9.7G  5.4G  3.9G  59% //dev/sda6              31G  1.9G   28G   7% /u02/dev/sda5              30G   21G  7.1G  75% /u01/dev/sda1             190M   23M  158M  13% /boottmpfs                1005M     0 1005M   0% /dev/shm/dev/sdb              504G  263G  216G  55% /u03/dev/sdc1             504G  312G  167G  66% /u04/u04/loop_mount      1008M   34M  924M   4% /u04/mount_loop创建dump备份目录[root@xitest01 u04]# mkdir backup[root@xitest01 u04]#  dump -0 -j -f /u04/backup/dump.bak /u04/loop_mount DUMP: Dumping /dev/sdc1 (/u04 (dir /loop_mount)) to /u04/backup/dump.bak  DUMP: Label: none  DUMP: Writing 10 Kilobyte records  DUMP: Compressing output at compression level 2 (bzlib)  DUMP: mapping (Pass I) [regular files]  DUMP: mapping (Pass II) [directories]  DUMP: estimated 1067027 blocks.  DUMP: Volume 1 started with block 1 at: Thu Feb  5 10:08:25 2015  DUMP: dumping (Pass III) [directories]  DUMP: dumping (Pass IV) [regular files]  DUMP: Closing /u04/backup/dump.bak  DUMP: Volume 1 completed at: Thu Feb  5 10:09:01 2015  DUMP: Volume 1 took 0:00:36  DUMP: Volume 1 transfer rate: 156 kB/s  DUMP: Volume 1 1067020kB uncompressed, 5627kB compressed, 189.626:1  DUMP: 1067020 blocks (1042.01MB) on 1 volume(s)  DUMP: finished in 36 seconds, throughput 29639 kBytes/sec  DUMP: Date of this level 0 dump: Thu Feb  5 10:08:25 2015  DUMP: Date this dump completed:  Thu Feb  5 10:09:01 2015  DUMP: Average transfer rate: 156 kB/s  DUMP: Wrote 1067020kB uncompressed, 5627kB compressed, 189.626:1  DUMP: DUMP IS DONE[root@xitest01 u04]# ls -l /u04/backup/total 5640-rw-r--r-- 1 root root 5762814 Feb  5 10:09 dump.bak[root@xitest01 u04]# du -sh /u04/backup/5.6M    /u04/backup/测试加入文件至目录[root@xitest01 u04]# cp ogg.tar.gz /u04/mount_loop/[root@xitest01 u04]# du -sh /u04/mount_loop/503M    /u04/mount_loop/[root@xitest01 u04]# dump -1 -j -f /u04/backup/dump.bak /u04/loop_mountDUMP: Only level 0 dumps are allowed on a subdirectory (不是单一文件系统)  DUMP: The ENTIRE dump is aborted.备份boot盘符测试[root@xitest01 u04]# dump -0 -j -f /u04/backup/dump_boot.bak  /dev/sda1[root@xitest01 u04]# dump -1 -j -f /u04/backup/dump_boo01.bak /dev/sda1 DUMP: WARNING: There is no inferior level dump on this filesystem  DUMP: WARNING: Assuming a level 0 dump by default (boot目录也没差异备份吗?)[root@xitest01 u04]# cd /u04/backup/[root@xitest01 backup]# lsdump.bak  dump_boo01.bak  dump_boot.bak[root@xitest01 backup]# du -sh *5.6M    dump.bak16M     dump_boo01.bak16M     dump_boot.bak   
DatabaseIpGzip Bzip2 
xxxxxxxx.xxx.xxx.xxx2015/3/22 10:22:00 ~2015/3/23 01:5600 3小時16GB2015/03/25 09:05~2015/03/26 00:56 16小時9.2GB
         

微信扫一扫

第七城市微信公众平台