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

学习笔记一:压缩
2015年2月5日
上午 10:23
压缩命令
压缩文件的扩展名大多是*.tar*.tar.gz*.tgz*.gz*.Z*.bz2
常见的压缩命令gzip与bzip2,其中bzip2压缩比gzip要好
tar可以用来进行文件打包,并可支持gzipbzip2的压缩
压缩 tar -jvc -f  filename.tar.bz2 /directory
查询 tar -jtv -f  filename.tar.bz2
解压 tar -jxv -f filename.tar.bz2 -C /puorose/directory
Dump 命令可备份文件系统或单一目录
Dump 的备份若针对文件系统时,可进行0~9level差异备份。其中level0为完整备份
restore命令可以还原被dump构建的备份文件
要新建光盘刻录数据时,可通过mkisofs命令来构建
可通过cdrecord来写入CDDVD刻录机
dd可备份完整的分区或磁盘,因为dd可读取硬盘的扇区表面数据
cpio为相当优秀的备份命令,不过必须要搭配类似find命令来读入预备份文件
测试演练
gzipbzip2压缩
 
tar打包
使用gzip压缩格式并且排除logbz压缩档
[oracle@xitest01 schema]$  tar -zcv -f schema_tar_test.tar.gz --exclude=/u03/schema/*.log --exclude=/u03/schema/*.bz   /u03/schema
使用bzip2压缩格式并且排除loggz压缩档
[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.bz2
260K    schema_tar_test.tar.gz
dump备份文件系统
模拟一个文件盘符
[root@xitest01 u04]# dd if=/dev/zero of=/u04/loop_mount bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 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 -h
Filesystem            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% /boot
tmpfs                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_mount
DUMP: 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]# ls
dump.bak  dump_boo01.bak  dump_boot.bak
[root@xitest01 backup]# du -sh *
5.6M    dump.bak
16M     dump_boo01.bak
16M     dump_boot.bak
 
 
 
Database
Ip
Gzip
 
Bzip2
 
xxxxx
xxx.xxx.xxx.xxx
2015/3/22 10:22:00 ~2015/3/23 01:5600 3小時
16GB
2015/03/25 09:05~2015/03/26 00:56 16小時
9.2GB
 
 
 
 
 
 
 
 
 
posted @ 2018-02-09 19:48  请点..头像  阅读(322)  评论(0编辑  收藏  举报