backup2l

 

介紹:

backup2l 是一個用來 backup 東西的 bash shell script 來

主要是提供了一個 "多層差異的備份" 策略 !

backup2l 會根據 name, modification time, size, ownership and permissions 去決定backup 什麼

 

Backup 的結構:

  1. full backup: 1, 2
  2. level-1 backups: 11, 12, 13 ...
  3. level-2 backups:  111, 112, 113 ...

112 是建基於 111, 111 是建基於 11, 11 是建基於 1

 


 

安裝:

apt-get install backup2l

 


 

設定:

/etc/backup2l.conf

VOLNAME="datahunter"                      <--- prefix for all output files
SRCLIST=(/etc /var/www/datahunter.org)    <--- Backup 什麼
SKIPCOND=(-path "*.nobackup*" -o -path "*.bak" -o -name "*.bak" -o -name "*.tmp")  <--- 什麼不 backup

BACKUP_DIR="/home/backup"

# Level 的設定

MAX_FULL=2
MAX_PER_LEVEL=6
MAX_LEVEL=1

GENERATIONS=2
CREATE_CHECK_FILE=1          <-- 自動建立 md5 的 check file

PRE_BACKUP (){...........}
POST_BACKUP (){.........}

AUTORUN=0
SIZE_UNITS=""                       <--- automatically
# UNCONFIGURED=1

# CREATE_DRIVER="DRIVER_MY_AFIOZ"  <--- Selects  an  archive  driver  for  creating  backups.
                                        default = "DRIVER_TAR_GZ"

 


 

Level Example:

 

  • VOLNAME="datahunter"
  • MAX_LEVEL=1
  • MAX_PER_LEVEL=6
  • MAX_FULL=2
  • GENERATIONS=2

backup2l -s

Summary
=======

Backup       Date       Time   |  Size   | Skipped  Files+D |  New  Obs. | Err.
------------------------------------------------------------------------------
datahunter.1 2012-08-04 06:25  |  210.5M |       3     5044 | 5044     0 |    0
datahunter.11 2012-08-05 06:25 |     66K |       3     5044 |    1     1 |    0
datahunter.12 2012-08-06 06:25 |    761K |       3     5044 |    3     3 |    0
datahunter.13 2012-08-07 06:25 |     66K |       3     5044 |    1     1 |    0
datahunter.14 2012-08-08 06:25 |    773K |       3     5044 |    3     3 |    0
datahunter.15 2012-08-09 06:25 |     66K |       3     5044 |    1     1 |    0
datahunter.16 2012-08-10 06:25 |    772K |       3     5044 |    5     5 |    0
datahunter.2 2012-08-11 06:25  |  210.6M |       3     5044 | 5044     0 |    0
datahunter.21 2012-08-12 06:25 |    778K |       3     5044 |    3     3 |    0
datahunter.22 2012-08-13 06:25 |     66K |       3     5044 |    1     1 |    0
datahunter.23 2012-08-13 20:49 |     66K |       3     5044 |    1     1 |    0
datahunter.24 2012-08-13 20:57 |     67K |       3     5045 |    2     1 |    0

 

MAX_FULL=2 是很重要的, 否則 GENERATIONS=2 會無舊的 Full backup

 

當 MAX_FULL=1 時, 而 GENERATIONS 又滿了, 下次行 backup2l 之後就到

Summary
=======

Backup       Date       Time  |  Size   | Skipped  Files+D |  New  Obs. | Err.
------------------------------------------------------------------------------
datahunter.1 2011-10-12 01:09 |  206.4M |       3     4909 | 4909     0 |    0

是的, 只餘下 datahunter.1

 

結論:

datahunter.1 -> datahunter.11 -> datahunter.12 ........... datahunter.16 -> datahunter.2

 


 

VOLNAME.BID 名稱:

1  -  -  -  -  -   |   MAX_PER_LEVEL
  MAX_LEVEL

         .

         .   GENERATIONS

         .

 


 

Restore 235

2

21, 22, 23

231, 232 ... 235

 


 

其他 Option:

 

backup2l  [ -c config ] [ -t backup-ID(BID) ] command

 

 -t, --time BID           <-- 自定  --locate and --restore

-c, --conf cofnig

 

 

-e, --estimate           <-- 測試下次 backup 的情況, 不會對現時的 backup 有影響

Estimating differential level-1 backup <datahunter.24> based on <datahunter.23>...
  1 / 4510 file(s), 1 / 535 dir(s), 10 B / 237.5MB (uncompressed)
  skipping: 2 file(s), 1 dir(s), 48KB (uncompressed)

 

-b, --backup  [ level ]           <-- 當 AUTORUN=1 時, 就是執行它.
                                                  加上 level 後, 即無視 MAX_LEVEL 的設定去做某 level 的 backup

 

-s, --get-summary

Summary
=======

Backup       Date       Time  |  Size   | Skipped  Files+D |  New  Obs. | Err.
------------------------------------------------------------------------------
datahunter.1 2012-08-04 06:25  |  210.5M |       3     5044 | 5044     0 |    0
datahunter.11 2012-08-05 06:25 |     66K |       3     5044 |    1     1 |    0
datahunter.12 2012-08-06 06:25 |    761K |       3     5044 |    3     3 |    0
datahunter.13 2012-08-07 06:25 |     66K |       3     5044 |    1     1 |    0
datahunter.14 2012-08-08 06:25 |    773K |       3     5044 |    3     3 |    0
datahunter.15 2012-08-09 06:25 |     66K |       3     5044 |    1     1 |    0
datahunter.16 2012-08-10 06:25 |    772K |       3     5044 |    5     5 |    0
datahunter.2 2012-08-11 06:25  |  210.6M |       3     5044 | 5044     0 |    0
datahunter.21 2012-08-12 06:25 |    778K |       3     5044 |    3     3 |    0
datahunter.22 2012-08-13 06:25 |     66K |       3     5044 |    1     1 |    0

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda5              19G  7.6G  8.6G  47% /

 

-a, --get-available [ pattern list ]  Shows all files removed and added for all backups.

backup2l -a /var/www/datahunter.org/testing            // 找出與 pattern 有關的檔案 + / -

Listing available files...
datahunter.24    +       10 08/13/12 20:56:11.7960966170 0000.0000 0644 /var/www/datahunter.org/testing
datahunter.25    -       10 08/13/12 20:56:11.7960966170 0000.0000 0644 /var/www/datahunter.org/testing
datahunter.25    +       10 08/13/12 20:56:11.7960966170 0000.0000 0644 /var/www/datahunter.org/testing.txt

 

-l, --locate [ pattern list ]                                                // 最近與 pattern有關的檔案在那裡

backup2l -l /var/www/datahunter.org/testing

Active files in <datahunter.25>: 1
  found in datahunter.25:    1   (    0 left)

Listing locations...
datahunter.25: /var/www/datahunter.org/testing.txt         <--- 我是想找沒有 .txt 的 ...

All required archive files are present in /home/backup.

 

-r, --restore [ pattern list ]       <--- 還原 file 相對於現在的目錄

backup2l -r 26

Active files in <datahunter.26>: 547
  found in datahunter.26:    0   (  547 left)
  found in datahunter.25:    0   (  547 left)
  found in datahunter.24:    0   (  547 left)
  found in datahunter.23:    0   (  547 left)
  found in datahunter.22:    0   (  547 left)
  found in datahunter.21:    0   (  547 left)
  found in datahunter.2:  547   (    0 left)

Restoring 57 directories...
Restoring files...
  datahunter.2.tar.gz: 547 file(s) using 'DRIVER_TAR_GZ'

 

-p, --purge BID list                    <-- 刪除某 backup, 並且刪除依賴它的 backup

backup2l -p 25

Purging <25>...
  removing <datahunter.25>
  removing <datahunter.26>

 

效檢:

-m, --make-check [ BID list ]    <-- 對 backup 檔建立 md5 檔(不用理, 因 config 有 "CREATE_CHECK_FILE=1")

-v, --verify [ BID list ]               <-- 檢查有 md5 檔的 backup

backup2l -v 24

Checking archive <datahunter.23>...
  ./datahunter.23.skipped.gz: OK
  ./datahunter.23.new.gz: OK
  ./datahunter.23.obsolete.gz: OK
  ./datahunter.23.error.gz: OK
  ./datahunter.23.tar.gz: OK
  ./datahunter.23.list.gz: OK
  datahunter.22.list.gz: OK

 

 

-x capacity max-free  BID-list                 // Split and collect files to be stored  on  removable media (--extract)

capacity: is the medium capacity in MB
max-free: empty space on each medium

The  operation  is interactive.

 

 


 

Daily backup

 

/etc/cron.daily/zz-backup2l

 

! which backup2l > /dev/null || nice -n 19 backup2l -b

 


 

VOLNAME.BID.list.gz

List of all active files when the backup was made.

 

VOLNAME.BID.new.gz

List  of  all  new ore modified files(Unless an error occured)

 

VOLNAME.BID.obsolete.gz

List of all obsolete files

 

VOLNAME.BID.skipped.gz

SKIPMASK

 

VOLNAME.BID.error.gz

generated by comparing the .new.gz file  with  the  actual  archive contents  using diff(1).

 

VOLNAME.BID.check

MD5 check sums of all files of the present archive(used by the --verify operation.)

cat datahunter.24.check

04b7fd6d20654b09ddb9439bee094af8  ./datahunter.24.skipped.gz
b2d1915f3695a6991d9c968c15b2c895  ./datahunter.24.new.gz
17db515df31f86054923a78cb327f1b3  ./datahunter.24.obsolete.gz
df05ebebc3950cd0cc33f3973744accf  ./datahunter.24.error.gz
428e441dc2448a072c88e1ad23230f44  ./datahunter.24.tar.gz
f64fe06f9fee4fe445bd402dc0d4729f  ./datahunter.24.list.gz
dfb385aa4c6677c5fc50e3bdb5a44e01  datahunter.23.list.gz

 

Creative Commons license icon Creative Commons license icon