2008年11月14日 星期五

用PAX做差異備份

PAX做差異備份


在windows的平台要設計出完整的備份方式要花不少錢買備份軟體才能做到,在非windows的平台上只要認真找一下,透過些指令就可以做到了


pax的一些基本用法:


pax遞迴複製目錄

pax –rwv –pe /home /root


/root目錄要是已存在的


後為複製到哪個目錄
前面為要複製的資料目錄


/home完整搬一份到/root





PAX做備份檔


pax -wvf /mnt/nfs/test/jackson.pax /home/jackson



察看備份檔內容


pax -vf /mnt/nfs/test/jackson.pax |more



還原備份檔


pax -rv -pe -f /mnt/nfs/test/jackson.pax


加上-i參數則為互動式還原


加上-pe為保留原檔案擁有者等屬性


還原時須注意:會將備份檔內的資料還原至原來的路徑下


例如:jackson.pas原本是從/home/Jackson備份而來的


就會還原回/home/Jackson,而覆蓋掉原來的檔案


所以若希望檔案不要直接被覆蓋,需先將原路徑的檔案做搬移或更名


完整備份範例


/home目錄做成一個備份檔:/backup/home.pax


pax -wvf /backup/home.pax /home



增量備份範例


/home目錄中,今天時間8:00之後有異動的資料做備份,


檔名為:/backup/home-diff.pax


Pax –wv –T 800 –f /backup/home-diff.pax /home


-T 參數使用:


-T [from_date][,to_date][/[c][m]]



Allow files to be
selected based on a file modification or inode change



time falling within a
specified time range of from_date to to_date (the



dates are inclusive).
If only a
from_date
is supplied, all files with a



modification or inode
change time equal to or younger are selected.
If



only
a to_date
is supplied, all files with a
modification or inode



change time equal to
or older will be selected. When the
from_date is



equal to the to_date,
only files with a modification or inode change



time of exactly that
time will be selected.






When pax is in the
write or copy mode, the optional trailing field



[c][m]
can be used to determine which file time (inode
change,
file
mod-



ification
or both) are used in the comparison. If neither is specified,



the
default is to use file modification time only
.
The m specifies the



comparison of file
modification time (the time when the file was last



written). The c
specifies the comparison of inode change time (the time



when the file inode
was last changed; e.g., a change of owner, group,



mode, etc). When c
and m are both specified, then the modification and



inode change times are
both compared. The inode change time comparison



is useful in selecting
files whose attributes were recently changed or



selecting files which
were recently created and had their modification



time reset to an older
time (as what happens when a file is extracted



from an archive and
the modification time is preserved). Time compar-



isons using both file
times is useful when pax is used to create a time



based incremental
archive (only files that were changed during a speci-



fied time range will
be archived).





A
time range is made up of six different fields and each field must
con-



tain two digits. The
format is:



[[[[[cc]yy]mm]dd]HH]MM[.SS]



Where cc is the first
two digits of the year (the century), yy is the



last two digits of the
year, the first mm is the month (from 01 to 12),



dd is the day of the
month (from 01 to 31), HH is the hour of the day



(from 00 to 23), MM is
the minute (from 00 to 59), and SS is the seconds



(from 00 to 59). The
minute field MM is required, while the other



fields are optional
and must be added in the following order:



HH, dd, mm, yy,
cc.



The SS field may be
added independently of the other fields. Time



ranges are relative to
the current time, so



-T 1234/cm



would select all files
with a modification or inode change time of 12:34



PM today or later.
Multiple -T time range can be supplied and checking



stops with the first
match.



增量備份檔的說明


假設有個目錄/home/account做完整備份建立了account.pax
大小為100MB


24小時候,其大小改變為150MB


則新的備份檔
account.pas才會產生,內容即為此150MB大小的資料


若經24小時做差異備份時,其大小未改變仍為100MB


則此次差異備份不對此檔案作備份





crontab的設定:


10:00 做一次完整備份


2到週日0:00做一次24小時的增量備份


以一個禮拜為循環


預計設定當做完完整備份時,把增量備份檔刪除


用以清出磁碟空間。



























沒有留言: