par2 ( 為檔案增加自我修復能力)

最後更新: 2020-09-21

 

介紹

 

Parchive  = parity archive

 + Par2 specification supports up to 32768 source blocks(equal-sized) and up to 65535 recovery blocks.

3 schemes for allocating recovery blocks to PAR2 files:

  • Variable (powers of 2 sizing scheme)(Default)
  • Variable (limited to size of largest data file)(-l)
  • All the same size(-u)

 


安裝

apt-get install par2

Windwos: quickpar

 


SYNOPSIS

 

par2 c|v|r [options] <PAR2 file> [files]

 


建立保護

 

# By defaults 係會用 16 MB RAM 去建立 5 % 的保護機制

# 並會以 block count: 2000 來分割來源

par2 create etch-openvz(clean).img.gz.000

Block size: 62436
Source file count: 1
Source block count: 2000
Redundancy: 5%
Recovery block count: 100    <= 2000 x 5%
Recovery file count: 7

Opening: etch-openvz(clean).img.gz.000
Computing Reed Solomon matrix.
Constructing: done.
Wrote 6243600 bytes to disk   <= 62436 x 100
Writing recovery packets
Writing verification packets
Done

# 由以上資料可知, 此機制可以修復 6243600 bytes 的總損壞,

# 而又唔超過 100 個 block 損害的地方, 不過, 每一個 block 都可以幾處受損  ^ ^

目錄內的檔案

-rw------- 1 root root 124847623 2009-01-27 20:53 etch-openvz(clean).img.gz.000
-rw------- 1 root root     40424 2009-01-27 17:32 etch-openvz(clean).img.gz.000.par2
-rw------- 1 root root    102928 2009-01-27 17:32 etch-openvz(clean).img.gz.000.vol000+01.par2
-rw------- 1 root root    205756 2009-01-27 17:32 etch-openvz(clean).img.gz.000.vol001+02.par2
-rw------- 1 root root    371088 2009-01-27 17:32 etch-openvz(clean).img.gz.000.vol003+04.par2
-rw------- 1 root root    661428 2009-01-27 17:32 etch-openvz(clean).img.gz.000.vol007+08.par2
-rw------- 1 root root   1201784 2009-01-27 17:32 etch-openvz(clean).img.gz.000.vol015+16.par2
-rw------- 1 root root   2242172 2009-01-27 17:32 etch-openvz(clean).img.gz.000.vol031+32.par2
-rw------- 1 root root   2554692 2009-01-27 17:32 etch-openvz(clean).img.gz.000.vol063+37.par2

 


一次過為多個檔案建立保護

 

cmd:

par2 create etch-openvz(clean).img.gz.000.*

 


進階設定
 

 

par2 create -r10 -s524288 -m64 etch-openvz(clean).img.gz.000

-r n                      # 建立幾多 % 的沉餘 (可以理解成 recovery 的 data size)

-r n<unit>            # Redundancy target size, <c>=g(iga),m(ega),k(ilo) bytes

-n n                     # 總共多小個 recovery file (可以理解成"最多容納多小個錯處")

-u                        # Uniform recovery file sizes

-s n                     # 每個 source block 的大小, Unit: byte

-m n                    # 要運用系統幾多 RAM, Unit: MB

ram 及 Block-Size 多了, 生成的速度可以大大提升,

而且 Block-Size 的增大, 令生成的檔案更接近應有的大小 ( 以上例子 10% 大 )

其他有用的 parameter

  • -b n      # Source Block Count (不能與 -s 一齊出現)
  • -l n       # 限制 recovery files 的 size  (不能與 -u / -n 一齊出現)

 


校檢檔案

par2 會生成出兩種檔案,

第一種叫 index 檔, 它並沒有還原能力, 但勝在細小,

我們可以用它來校檢目標是否正確, 及找出要那幾個 parity volumes 檔

第二種是 parity volumes 檔, 它是俱有還原能力的,

而且每個檔案都俱有不同程度的還原能力,

我們可以視乎檔案的損壞程度而選用某幾個 parity volumes 檔

i.e.

par2 verify etch-openvz(clean).img.gz.000.par2

校檢成功:

Verifying source files:
Target: "etch-openvz(clean).img.gz.000" - found.
All files are correct, repair is not required.

P.S.

par2 它是不會檢查 metadata 的, 亦即是說, 如果 permission 有變, 佢係唔知架 ~

 


parity volumes 檔案名的格式

 

檔案名: 原來的檔案名.volxx+yy

i.e.

filename.par2
filename.vol000+01.PAR2
filename.vol001+02.PAR2
filename.vol003+04.PAR2
filename.vol007+06.PAR2

 * Each of the files contains a different number of recovery blocks.

 * Each successive PAR2 file has approximately twice as many recovery blocks as the previous one.

xx:

000000       0     # 第0個 recovery block
000001       1     # 第1個及第2個 recover block
000011       3     # 第3個至第6個 recover block
000111       7
001111      15
011111      31
111111      63

block number of the first recovery block in that file. 此格式方法日後追加 recovery block

比如已經有 5% 沉餘, 現在在追加 5%, 令總共有 10% 沉餘

yy:

2^0, 2^1, 2^2, 2^3 ............

1, 2, 4, 8 ......... 它們是指每個 parity volumes 檔內含幾多個 recovery block

 


修復受損

 

當 verify 時見到以下內容

Repair is required.
1 file(s) exist but are damaged.
You have 1999 out of 2000 data blocks available.
You have 100 recovery blocks available.
Repair is possible.
You have an excess of 99 recovery blocks.
1 recovery blocks will be used to repair.

由以上資料可知, 任何一個  parity volumes 檔都可以幫到你 ^ ^

但如果結果係 "6 recovery blocks will be used to repair."

表示你最少要有

etch-openvz(clean).img.gz.000.vol003+02.par2
etch-openvz(clean).img.gz.000.vol003+04.par2

又或者一個

etch-openvz(clean).img.gz.000.vol007+08.par2

修補所用的 cmd

par2 repair test.mpg.par2

當修補成功後,它會再一次檢查檔案的原整性, 真是相當細心, 所以大可效心 ^ ^

 


 

 

 

Creative Commons license icon Creative Commons license icon