天天看點

Linux打包和壓縮技術

  • 對于檔案進行壓縮,可以大幅度減少占用的磁盤空間,這就是大量的壓縮軟體盛行的原因;
  • 對于不同的壓縮格式通常使用不同的字尾名稱來進行差別;
    • *.Z

      :使用

      compress

      壓縮之後的檔案;
    • .gz

      :使用

      gzip

      壓縮之後的程式;
    • .bz2

      :使用

      bzip2

      壓縮之後的程式;
    • .tar

      :使用

      tar

      打包的程式,并沒有進行壓縮;
    • .tar.gz

      :使用

      tar

      進行打包,然後使用

      gzip

      進行壓縮;
    • .tar.bz2

      :使用

      tar

      進行打包,然後使用

      bzip

      進行壓縮;
  • 打包:表示的是将多個檔案歸檔成為一個檔案,并不會改變實際的大小;
  • 壓縮表示的是使用具體的壓縮算法,改變檔案占據磁盤空間的具體大小;
  • 常見的壓縮指令
    • compress

      :通常需要安裝

      yum install ncompress -y

      ;
      • -r

        :用于進行第歸壓縮,對于目錄和目錄裡面的内容都進行壓縮;
      • -c

        :将壓縮之後的資料輸出到标準螢幕;
      • -v

        :用于顯示壓縮檔案的過程;
      • -d

        :可以用于直接解壓壓縮檔案;
[[email protected] ~]# compress -r ./ 
[[email protected] ~]# ls
anaconda-ks.cfg.Z  install.log.syslog.Z  install.log.Z
對于壓縮之前的檔案就進行删除;
           
  • 進行解壓縮
[[email protected] ~]# ls
anaconda-ks.cfg  install.log  install.log.syslog.Z
[[email protected] ~]# uncompress install.log.syslog.Z 
[[email protected] ~]# ls
anaconda-ks.cfg  install.log  install.log.syslog
           
  • gzip

    :可以用于解壓縮

    compress zip,gzip

    等軟體格式壓縮的檔案,壓縮後的檔案是

    *.gz

    ;
    • -c

      :講壓縮後的資料輸出到螢幕上,可以通過劉重定向進行儲存;
    • -d

      :可以用于解壓縮上述格式對應的檔案;
    • -t

      用于檢查壓縮檔案的一緻性,檢視檔案有無錯誤;
    • -v

      :用于檢查源檔案和壓縮檔案的的壓縮比資訊;
    • -#

      :用于指定壓縮等級,

      -1

      最快,

      -9

      最慢,最好的壓縮比是

      -6

      ;
-bash-# gzip -v passwd 
passwd:  59.2% -- replaced with passwd.gz
-bash-# gzip -t passwd.gz 
-bash-# gzip -d passwd.gz 
           
  • 對于小檔案指定壓縮等級并不是很明顯
-bash-# gzip -9 -c passwd -v > passwd.gz
passwd:  59.2%
           
  • gzip

    具備

    compress

    提供的功能,并且能夠提供更發達的壓縮比,是以相比于

    compress

    建議使用

    gzip

    ;
  • bzip2

    一個比

    gzip

    功能更加強大的指令;
    • -c

      :将壓縮過程中産生的資料,輸出到螢幕上面;
    • -d

      :表示用于解壓縮的參數;
    • -k

      :表示保留源檔案,不删除源檔案;
    • -z

      用于進行壓縮的參數;
    • -v

      :用于顯示壓縮比資訊;
    • -#

      :用于顯示壓縮比的參數,

      -9

      最慢,

      -1

      最快;
[root@server8 mnt]# bzip2 -z -9 -v passwd 
 passwd:   :,   bits/byte, % saved,  in,  out.
 [root@server8 mnt]# bzip2 -d passwd.bz2 
[root@server8 mnt]# ls
passwd
           
  • 這個指令支援,保留源檔案的選項
[[email protected] mnt]# bzip2 -z -9 -v -k passwd 
  passwd:   :,   bits/byte, % saved,  in,  out.
[roo[email protected] mnt]# ls
passwd  passwd.bz2
           
  • bzip2

    通常可以用來解壓縮

    .bz,.bz2,.tbz,.tbz2

    壓縮個是的檔案,通常需要使用

    -d

    選項;
  • 對于使用

    bzip2

    壓縮的檔案,可以不進行解壓縮來檢視檔案裡面的内容
[root@server8 mnt]# bzcat passwd.bz2 
root:x:::root:/root:/bin/bash
bin:x:::bin:/bin:/sbin/nologin
daemon:x:::daemon:/sbin:/sbin/nologin
adm:x:::adm:/var/adm:/sbin/nologin
lp:x:::lp:/var/spool/lpd:/sbin/nologin
sync:x:::sync:/sbin:/bin/sync
shutdown:x:::shutdown:/sbin:/sbin/shutdown
halt:x:::halt:/sbin:/sbin/halt
           
  • 打包指令

    tar

  • 上面的壓縮檔案的指令,通常是對于單個檔案或者是一個目錄裡面的所有檔案進行壓縮,壓縮之後,仍然是多個檔案,如果需要壓縮後是一個檔案,那麼就需要使用歸檔指令,首先對于上述檔案進行歸檔,然後進行壓縮;
  • tar

    指令的使用:
    • -c

      :用于建立歸檔檔案,通常和

      -v

      選項一起使用,用于顯示檔案的歸檔過程;
    • -t

      :用于檢視打封包件包含那些檔案名;
    • -x

      :用于解打包或者解壓縮,通常和

      -C

      一起使用,用于指定解壓縮之後的檔案路徑;
    • -j

      :表示對于

      *.tar.bz2

      進行解壓縮,或者建立

      *.tar.bz2

      ;
    • -z

      :表示對于

      *.tar.gz

      進行解壓縮,或者建立

      *.tar.gz

    • -v

      :顯示過程的詳細資訊,,也就是顯示正在處理的檔案名稱;
    • -C

      :用于指定解壓縮之後的特定目錄;
    • -p

      :标志保留之前的權限;
    • -P

      :表示保留絕對路徑;
  • 首先建立歸檔并且诶壓縮的檔案
原來目錄裡面檔案的大小
[root@server8 mnt]# du -h ./etc | tail -1
M ./etc
[root@server8 mnt]# du -smh ./etc
M ./etc
[root@server8 mnt]# ll -h
drwxr-xr-x.  root root K 月   09: etc
-rw-r--r--.   root root M 月   09: etc.tar.bz2
           
  • 使用

    tar

    并結合壓縮的方式來進行系統備份
  • 首先來備份

    /etc

    檔案,需要注意到下面的資訊
[[email protected] mnt]# tar -zpcv -f /root/etc.tar.gz /etc/
tar: Removing leading `/' from member names
           
  • 為什麼需要移除

    /

    這個過程,這個主要是為了系統安全,如果不移除,那麼在進行解壓縮時,就覆寫原來路徑下面的内容,如果去掉,那麼可以将上述壓縮的檔案解壓到指定的目錄裡面,選擇合适的進行;
  • 如果需要保留根目錄需要指定

    -p

    選項;
[root@server8 mnt]# tar -jpPcvf /root/etc.and.tar.bz2 /etc/
/etc/
/etc/statetab
/etc/gai.conf
.....
           
  • 如果進行解壓縮檔案,就會覆寫

    /

    目錄裡面的内容;
  • 檢視壓縮包裡面的檔案
[[email protected] mnt]# tar -jtf /root/etc.and.tar.bz2 | less
/etc/
/etc/statetab
/etc/gai.conf
/etc/gshadow
/etc/inputrc
/etc/sudo-ldap.conf
/etc/printcap
/etc/samba/
/etc/samba/smb.conf
/etc/samba/lmhosts
/etc/libuser.conf
/etc/rsyslog.conf
/etc/exports
/etc/filesystems
/etc/group-
/etc/aliases
/etc/bashrc
/etc/request-key.conf
/etc/postfix/
/etc/postfix/transport
/etc/postfix/relocated
/etc/postfix/canonical
/etc/postfix/access
.....
           
  • -C

    這個指令是很常用,用于指定檔案的解壓位置;
[root@server8 mnt]# tar -jxvf etc.tar.bz2 -C /tmp/
[root@server8 mnt]# du -smh /tmp/etc/
M /tmp/etc/
           
  • 關于解壓縮的幾個特殊用法
  • 僅僅用于解開單一檔案的用法
首先找到需要解壓的檔案的具體名稱
[[email protected] mnt]# tar -jtv -f etc.tar.bz2 | grep 'shadow' 
---------- root/root        -- 09: ./etc/gshadow
---------- root/root        -- 09: ./etc/shadow-
---------- root/root        -- 09: ./etc/shadow
-rw------- root/root        -- 09: ./etc/gshadow-
[[email protected] mnt]# tar -jxv -f ./etc.tar.bz2 ./etc/shadow
./etc/shadow
[[email protected] mnt]# ll etc
total 4
----------.  root root  月   09: shadow
           
  • 打包壓縮某個目錄但是不打包壓縮一些檔案
[[email protected] mnt]# tar -jcvf mnt.tar.bz2 --exclude=/mnt/etc.tar.bz2 --exclude=passwd.bz2 /mnt/ /mnt/etc
tar: Removing leading `/' from member names
/mnt/
/mnt/etc/
/mnt/etc/shadow
/mnt/passwd
/mnt/tar
/mnt/etc/
/mnt/etc/shadow
[[email protected] mnt]# ls
etc  etc.tar.bz2  mnt.tar.bz2  passwd  passwd.bz2  tar
           
  • 僅僅備份某個時刻之後的檔案
[[email protected] mnt]# tar -jvc -f /mnt/newer.bz2 --newer-mtime="20180209" /etc/*
tar: /etc/X11/prefdm: file is unchanged; not dumped
/etc/X11/applnk/
/etc/X11/fontpath.d/
/etc/xdg/
/etc/xdg/autostart/
tar: /etc/xdg/autostart/restorecond.desktop: file is unchanged; not dumped
/etc/xinetd.d/
/etc/yum/
/etc/yum/vars/
tar: /etc/yum/version-groups.conf: file is unchanged; not dumped
/etc/yum/pluginconf.d/
tar: /etc/yum/pluginconf.d/subscription-manager.conf: file is unchanged; not dumped
tar: /etc/yum/pluginconf.d/product-id.conf: file is unchanged; not dumped
tar: /etc/yum/pluginconf.d/rhnplugin.conf: file is unchanged; not dumped
/etc/yum/protected.d/
tar: /etc/yum.conf: file is unchanged; not dumped
/etc/yum.repos.d/
/etc/yum.repos.d/rhel6_high.repo
....

裡面包含衆多的檔案
[[email protected] mnt]# tar -jtf /mnt/newer.bz2 | grep -v '/$'
etc/adjtime
etc/aliases.db
etc/alternatives/libiptc000.x86_64
etc/alternatives/mta-sendmail
etc/alternatives/man-iptables-save.x86_64
etc/alternatives/mta-aliasesman
etc/alternatives/mta-mailqman
...........
           
  • 強大的

    dump

    指令
  • 不僅僅可以用于檔案系統備份,也可以用來進行目錄的備份,并且是一個允許定制等級的備份工具;
  • 提供

    dump

    指令的軟體包是

    dump-0.4-0.6.b42.el6.x86_64

    ,這個軟體包需要提前進行安裝;
  • 當備份的資料是單一的檔案系統時,可以使用完整的

    dump

    功能,并且可以使用

    0~9

    指定不同的等級,備份的參數可以選擇裝置檔案名稱或者是挂載點;
  • 當備份的和資料僅僅是一個目錄而不是檔案系統時,需要滿足下列條件:
    • 1.所有的備份資料都必須在需要備份的目錄裡面;
    • 2.并且之能夠使用

      level 0

      ,也就是僅僅支援完整備份;
  • dump

    指令支援的選項
    • -S

      :表示僅僅列出備份後面的資料需要多少磁盤,但是不進行備份操作;
    • -u

      :表示将這次的備份時間記錄在

      /etc/dumpdates

      檔案裡面;
    • -v

      :表示

      dump

      指令的執行過程;
    • -j

      :表示對于執行的檔案進行壓縮,壓縮格式為

      *.bz2

      ,預設的壓縮等級為

      2

      ;
    • -level

      :表示進行資料備份的等級;
    • -f

      :用于指定備份産生的檔案名稱;
    • -W

      :用于列出

      /etc/fstab

      裡面的檔案是否對有

      dump

      執行的分區進行備份過;
  • 找出目前系統最小的檔案系統
  • 首先找出最小的檔案系統
[root@server8 mnt]# df -h 
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root  7.5G  1.1G  6.1G  15% /
tmpfs                         M       M   % /dev/shm
/dev/vda1                     M   M  M   % /boot
           
  • 鑒于

    tmpfs

    是一個臨時的檔案系統,這裡僅僅對于

    /dev/vda1

    這個系統來進行完整備份

    [level 0]

  • 測試進行完整備份需要多大的空間來完成
[root@server8 mnt]# dump -S /dev/vda1 

大約需要MB來完成完整備份操作
           
  • 這個時執行完整備份的過程
[[email protected] mnt]# dump -0s /root/boot.dump /boot/
dump: illegal tape size -- /root/boot.dump
[[email protected] mnt]# dump -0u -f /root/boot.dump /boot/
  DUMP: Date of this level  dump: Sat Mar  :: 
  DUMP: Dumping /dev/vda1 (/boot) to /root/boot.dump
  DUMP: Label: none
  DUMP: Writing  Kilobyte records
  DUMP: mapping (Pass I) [regular files]
  DUMP: mapping (Pass II) [directories]
  DUMP: estimated  blocks.
  DUMP: Volume  started with block  at: Sat Mar  :: 
  DUMP: dumping (Pass III) [directories]
  DUMP: dumping (Pass IV) [regular files]
  DUMP: Closing /root/boot.dump
  DUMP: Volume  completed at: Sat Mar  :: 
  DUMP: Volume   blocks (MB)
  DUMP:  blocks (MB) on  volume(s)
  DUMP: finished in less than a second
  DUMP: Date of this level  dump: Sat Mar  :: 
  DUMP: Date this dump completed:  Sat Mar  :: 
  DUMP: Average transfer rate:  kB/s
  DUMP: DUMP IS DONE
           
  • 關于各個參數的含義在上面已經解釋過的;
  • 檢視系統生成的關于備份的日志檔案
[root@server8 mnt]# cat /etc/dumpdates 
/dev/vda1  Sat Mar  ::  +080
           
  • 各個字段表示的含義
/dev/vda1:表示進行完整備份的裝置,或者檔案系統
0:表示執行備份的等級;
Sat Mar 17 14:31:30 2018:表示執行備份的時間
           
  • 系統可能存在的沒有進行使用指令

    dump

    進行備份過的檔案
[[email protected] mnt]# dump -W
Last dump(s) done (Dump '>' file systems):
> /dev/mapper/VolGroup-lv_root  (     /) Last dump: never
  /dev/vda1 ( /boot) Last dump: Level , Date Sat Mar  :: 
           
  • 準備執行差異備份,首先需要修改檔案,這裡使用強大的

    dd

    指令,模拟發生檔案修改的大小大約為

    10MB

    ;
[[email protected] mnt]# dd if=/dev/zero of=/boot/test.img bs=1M count=10
+ records in
+ records out
 bytes ( MB) copied,  s,  GB/s
           
  • 接下來進行差異備份

    [level 1]

[[email protected] mnt]# dump -1u -f /root/boot.dump.1 /boot/
  DUMP: Date of this level  dump: Sat Mar  :: 
  DUMP: Date of last level  dump: Sat Mar  :: 
  DUMP: Dumping /dev/vda1 (/boot) to /root/boot.dump
  DUMP: Label: none
  DUMP: Writing  Kilobyte records
  DUMP: mapping (Pass I) [regular files]
  DUMP: mapping (Pass II) [directories]
  DUMP: estimated  blocks.
  DUMP: Volume  started with block  at: Sat Mar  :: 
  DUMP: dumping (Pass III) [directories]
  DUMP: dumping (Pass IV) [regular files]
  DUMP: Closing /root/boot.dump
  DUMP: Volume  completed at: Sat Mar  :: 
  DUMP: Volume   blocks (MB)
  DUMP:  blocks (MB) on  volume(s)
  DUMP: finished in less than a second
  DUMP: Date of this level  dump: Sat Mar  :: 
  DUMP: Date this dump completed:  Sat Mar  :: 
  DUMP: Average transfer rate:  kB/s
  DUMP: DUMP IS DONE
           
  • 這裡的檢視的備份等級就已經發生改變
[[email protected] mnt]# dump -W
Last dump(s) done (Dump '>' file systems):
> /dev/mapper/VolGroup-lv_root  (     /) Last dump: never
  /dev/vda1 ( /boot) Last dump: Level , Date Sat Mar  :: 
           
  • dump備份單一目錄的方法
  • 因為對于目錄的備份之能夠使用

    level 0

    ,并且不支援

    -u

    選項,那麼直接對于這個目錄進行備份
[[email protected] mnt]# dump -0j -f /mnt/etc.dump.bz2 /etc/
  DUMP: Date of this level  dump: Sat Mar  :: 
  DUMP: Dumping /dev/mapper/VolGroup-lv_root (/ (dir etc)) to /mnt/etc.dump.bz2
  DUMP: Label: none
  DUMP: Writing  Kilobyte records
  DUMP: Compressing output at compression level  (bzlib)
  DUMP: mapping (Pass I) [regular files]
  DUMP: mapping (Pass II) [directories]
  DUMP: estimated  blocks.
  DUMP: Volume  started with block  at: Sat Mar  :: 
  DUMP: dumping (Pass III) [directories]
  DUMP: dumping (Pass IV) [regular files]
  DUMP: Closing /mnt/etc.dump.bz2
  DUMP: Volume  completed at: Sat Mar  :: 
  DUMP: Volume  took ::
  DUMP: Volume  transfer rate:  kB/s
  DUMP: Volume  kB uncompressed, kB compressed, :
  DUMP:  blocks (MB) on  volume(s)
  DUMP: finished in  seconds, throughput  kBytes/sec
  DUMP: Date of this level  dump: Sat Mar  :: 
  DUMP: Date this dump completed:  Sat Mar  :: 
  DUMP: Average transfer rate:  kB/s
  DUMP: Wrote kB uncompressed, kB compressed, :
  DUMP: DUMP IS DONE
           
  • 關于簡單的備份恢複的指令
  • restore

    對于使用

    dump

    備份的檔案,使用

    restore

    指令來進行恢複
    • -t

      :表示僅僅用于檢視備份檔案裡面包含那些重要檔案,不執行恢複操作;
    • -C

      :用于列出使用

      dump

      備份的備份檔案裡面和目前對應的檔案系統存在哪些是不一樣的;
    • -i

      :表示進入互動模式,用于選擇還原哪些檔案;
    • -r

      :将整個檔案系統進行還原,使用

      dump

      進行的備份進行還原;
    • -h

      :用于檢視備份資料中的

      inode

      資訊和

      label

      資訊;
    • -f

      :表示需要處理的

      dump

      檔案;
    • -D

      :通常和

      -C

      一起使用,用于後面的挂載點和

      dump

      内部不同的檔案;
  • 用于檢視

    dump

    指令的備份裡面包含的内容
[[email protected] mnt]# restore -t -f /root/boot.dump
Dump   date: Sat Mar  :: 
Dumped from: the epoch
Level  dump of /boot on server8.com:/dev/vda1
Label: none
           .
          ./lost+found
       ./grub
       ./grub/grub.conf
       ./grub/splash.xpm.gz
       ./grub/menu.lst
       ./grub/device.map
       ./grub/stage1
       ./grub/stage2
       ./grub/e2fs_stage1_5
       ./grub/fat_stage1_5
       ./grub/ffs_stage1_5
       ./grub/iso9660_stage1_5
     ........
           
  • 上面兩列資訊分别表示的是

    inode

    資訊以及檔案名稱資訊;
  • 檢視目前檔案系統和使用

    dump

    備份的檔案系統之間的差異
  • 首先嘗試修改檔案系統裡面的内容
  • 然後使用指令檢視兩者之間的差異
[[email protected] boot]# restore -C -f /root/boot.dump
Dump   date: Sat Mar  :: 
Dumped from: the epoch
Level  dump of /boot on server8.com:/dev/vda1
Label: none
filesys = /boot
restore: unable to stat ./config--el6.x86_64: No such file or directory
Some files were modified!   compare errors
           
  • 上面表示在查找

    ./config-2.6.32-431.el6.x86_64: No such file or directory

    時,不存在,表示這個檔案被修改了,這個不是很明顯,在這個檔案裡面添加一些資訊
[root@server8 boot]# vim config-2.6.32-431.el6.x86_64 
# restore resting
#
           
  • 再次使用上面的指令比較檔案之間的差異
[[email protected] boot]# restore -C -f /root/boot.dump
Dump   date: Sat Mar  :: 
Dumped from: the epoch
Level  dump of /boot on server8.com:/dev/vda1
Label: none
filesys = /boot
./config--el6.x86_64: tape and disk copies are different
Some files were modified!   compare errors
           
  • 這次明确的提示

    ./config-2.6.32-431.el6.x86_64

    被修改了;
  • 執行還原的過程,首先需要建立立一個檔案系統然後進行還原
  • 首先進行分區的建立以及格式化
[[email protected] boot]# fdisk /dev/vdb 
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier .
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag  of partition table  will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (-)
p
Partition number (-): 
First cylinder (-, default ): 
Using default value 
Last cylinder, +cylinders or +size{K,M,G} (-, default ): +G

Command (m for help): p

Disk /dev/vdb:  MB,  bytes
 heads,  sectors/track,  cylinders
Units = cylinders of  *  =  bytes
Sector size (logical/physical):  bytes /  bytes
I/O size (minimum/optimal):  bytes /  bytes
Disk identifier: 

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1                            +    Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[[email protected] boot]# partx /dev/vdb
# 1:        63-  2098655 (  2098593 sectors,   1074 MB)
# 2:         0-       -1 (        0 sectors,      0 MB)
# 3:         0-       -1 (        0 sectors,      0 MB)
# 4:         0-       -1 (        0 sectors,      0 MB)
[[email protected] boot]# mkfs.ext3 /dev/vdb1 
mke2fs  (-May-)
warning:  blocks unused.

Filesystem label=
OS type: Linux
Block size= (log=)
Fragment size= (log=)
Stride= blocks, Stripe width= blocks
 inodes,  blocks
 blocks (%) reserved for the super user
First data block=
Maximum filesystem blocks=
 block groups
 blocks per group,  fragments per group
 inodes per group
Superblock backups stored on blocks: 
    , , , 

Writing inode tables: done                            
Creating journal ( blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every  mounts or
 days, whichever comes first.  Use tune2fs -c or -i to override.
           
  • 然後使用指令進行還原操作
[[email protected] mnt]# restore -r -f /root/boot.dump
restore: ./lost+found: File exists
[[email protected] mnt]# ls
config--el6.x86_64         restoresymtable
efi                                  symvers--el6.x86_64.gz
grub                                 System.map--el6.x86_64
initramfs--el6.x86_64.img  vmlinuz--el6.x86_64
           
  • 這個過程是一次性将所有檔案進行還原的,也可以執行互動模式選擇檔案進行還原
[[email protected] mnt]# restore -i -f /root/boot.dump
restore > ls
.:
.vmlinuz--el6.x86_64.hmac  initramfs--el6.x86_64.img 
System.map--el6.x86_64     lost+found/
config--el6.x86_64         symvers--el6.x86_64.gz 
efi/                                 vmlinuz--el6.x86_64 
restore > add  .vmlinuz--el6.x86_64.hmac initramfs--el6.x86_64.img

restore > add  vmlinuz--el6.x86_64  
restore > ls
.:
*.vmlinuz--el6.x86_64.hmac  *initramfs--el6.x86_64.img 
 System.map--el6.x86_64      lost+found/
 config--el6.x86_64          symvers--el6.x86_64.gz 
 efi/                                 *vmlinuz--el6.x86_64 
 restore > extract  
You have not read any volumes yet.
Unless you know which volume your file(s) are on you should start
with the last volume and work towards the first.
Specify next volume # (none if no more volumes): 1
set owner/mode for '.'? [yn] n
[[email protected] mnt]# ls -al
total 
dr-xr-xr-x.   root root      月   : .
dr-xr-xr-x.  root root      月   : ..
-rw-------.   root root  月   : initramfs--el6.x86_64.img
-rwxr-xr-x.   root root   月   vmlinuz--el6.x86_64
-rw-r--r--.   root root       月   .vmlinuz--el6.x86_64.hmac 
           
  • add

    表示添加需要解壓縮的檔案,

    delete

    表示删除解壓縮清單中的檔案,不删除備份的檔案,

    extract

    表示按照上面的要求進行解壓縮操作
  • 關于神奇的dd指令
  • dd

    指令可以直接對于某個扇區的檔案進行操作
    • if

      :表示

      input file

      ,也就是輸入的檔案,可以是裝置;
    • of

      :表示

      output file

      ,表示輸出檔案,也可以是裝置;
    • bs

      :表示

      blosk size

      ,預設為一個扇區的大小

      512bytes

      ;
    • count

      :表示備份

      bs

      的數量;
  • 可以執行的幾種備份
  • 檔案備份
[[email protected] mnt]# dd if=/etc/passwd of=/mnt/passwd.back
+ records in
+ records out
 bytes ( kB) copied,  s,  MB/s
           
  • 第一個扇區備份,因為包含

    MBR 446位元組

    ,

    分區表 64

    位元組的備份,
[[email protected] mnt]# dd if=/dev/vda of=/mnt/first_sector.back bs=512 count=1
+ records in
+ records out
 bytes ( B) copied,  s,  MB/
           
  • 如果僅僅備份

    MBR

    執行
[[email protected] mnt]# dd if=/dev/vda of=/mnt/first_sector.back bs=446 count=1
+ records in
+ records out
 bytes ( B) copied,  s,  MB/s
           
  • 接下來備份一個分區的資料到另一分區上面
[[email protected] /]# fdisk -l /dev/vda1 
Disk /dev/vda1:  MB,  bytes
 heads,  sectors/track,  cylinders
Units = cylinders of  *  =  bytes
Sector size (logical/physical):  bytes /  bytes
I/O size (minimum/optimal):  bytes /  bytes
Disk identifier: 


[[email protected] /]# fdisk /dev/vdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (-)
p
Partition number (-): 
First cylinder (-, default ): 
Using default value 
Last cylinder, +cylinders or +size{K,M,G} (-, default ): +G

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[[email protected] /]# partx /dev/vdb
# 1:        63-  2098655 (  2098593 sectors,   1074 MB)
# 2:   2098656- 10488239 (  8389584 sectors,   4295 MB)
# 3:         0-       -1 (        0 sectors,      0 MB)
# 4:         0-       -1 (        0 sectors,      0 MB)

[[email protected] /]# fdisk -l /dev/vdb2

Disk /dev/vdb2:  MB,  bytes
 heads,  sectors/track,  cylinders
Units = cylinders of  *  =  bytes
Sector size (logical/physical):  bytes /  bytes
I/O size (minimum/optimal):  bytes /  bytes
Disk identifier: