Chinaunix首页 | 论坛 | 博客
  • 博客访问: 197985
  • 博文数量: 78
  • 博客积分: 1580
  • 博客等级: 上尉
  • 技术积分: 635
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-27 11:06
文章分类

全部博文(78)

文章存档

2007年(6)

2006年(72)

我的朋友
最近访客

分类:

2006-08-14 10:44:06


Backup Tools in UNIX(Linux)

bullet 本文介紹UNIX(Linux)系統中常用的備份工具(tar,cpio,dump,dd),這些工具設計目的主要在將資料備份至磁帶中。然而近年來由於硬碟容量大幅提升,價格則大幅的滑落,將資料備份至硬碟也是一個不錯的選擇。同時為了講解方便,本文範例全部以硬碟備份為主。
 
bullet tar
bullet Command Format:
tar options [argument] filenames
tar將filenames所指定的檔案,備份至所指定的目的地 - a tarfile(A tape for default)
 
bullet 常用options:
c: 建立一個back archive file ( From the filenames)
t:  列出tarfile的內容
x: tarfile 中還原所有檔案
v: verbal mode
f: 指定tarfile的檔名,若忽略此一選項,則將tarfile指向預設磁帶
z:壓縮(When Backup),解壓縮(When restore)
 
bullet Examples:

Example 1 (Full Backup)

[woody@nmc /home]$ tar cvf /data/woody.tar /home/woody
將/home/woody整個目錄(含子目錄)備份至檔案/data/woody.tar

[woody@nmc /home]$ tar tvf /data/woody.tar
檢視/data/woody.tar 所含的檔案資訊

[woody@nmc /home]$ tar cvfz  /data/etc_bin_sbin.tar  /etc  /bin /sbin
將/etc, /bin及/sbin三個目錄(含子目錄)下的所有檔案,以壓縮格式備份至檔案/data/etc_bin_sbin.tar.gz

Example 2  (Incremental Backup)

[root@nmc /home]# tar cf /data/etc2.tar `find /etc -mtime -1 ! -name '*.o' ! -type d -print`
將/etc目錄下,最近24小時(1天)內曾經被更動過內容(包括新增)所有檔案,備份至/data/etc2.tar
(如果sourcefiles list中包含目錄名稱,tar會將該目錄下所有目錄及檔案一概備份,因此利用tar進行incremental backup時,必須去除所有目錄,否則將會失去該有的準確性)

Example 3 (Restore)

[root@nmc /home]# cd /tmp
[root@nmc /tmp]# tar xvf /data/etc2.tar
將原先備份至/data/etc2.tar的檔案還原至目錄/tmp下(包含所有檔案結構)
 
bullet tar is the easiest way of backup to use with directory subtree.
 
bullet tar is not that powerful as dump, but is sufficient for systems with relatively small amount of critical data.
 
bullet cpio
bullet cpio可以用來將檔案複製到一個架構檔案中,或者從一個架構檔案中複製出一個檔案。
cpio運作可以分成三個模式:copy-out, copy-in及copy-pass.
 
bullet copy-out運作模式 - with option -o
copy-out模式用來將檔案複製至archive檔案中,執行時由標準輸入讀入檔案清單(一個檔案獨立一行),並將archive檔案寫至標準輸出。使用copy-out模式備份時,必須運用輸出轉向技巧,將archive檔案轉向至磁帶,或硬碟中的一個檔案。

Examples:

Example1: (Full Backup)

[root@nmc /tmp]#find /etc -print | cpio -o > /data/etc.cpio
##
/etc目錄下所有檔案備份至/data/etc.cpio

Example2:(Incremental Backup)

[root@nmc /tmp]#find /etc -mtime -1 ! -name "*.o" -print|cpio -o > /data/etc1.cpio
##將/etc目錄下,最近24小時(1天)內曾經被更動過內容(包括新增)所有檔案,備份至/data/etc1.cpio

Example3:(Incremental Backup)

[root@nmc /data]# touch /data/etc_full
##紀錄Full Backup時間
[root@nmc /data]# find /etc -print |cpio -o > /data/etc.cpio
##A Full Backup
A day after
[root@nmc /data]#find /etc -newer /data/etc_full -print|cpio -o > /data/etc_1.cpio
## A level 1 incremental backup
 
bullet copy-in運作模式 - with option -i
copy-in模式用來將檔案由archive檔案中複製出,執行時由標準輸入讀入archive檔案內容,並依據命令列中非選項的參數(檔案清單),取出archive中的檔案。

Example1:(Restore a single fie)

[root@nmc /data]# cpio -im /etc/passwd < /data/etc.cpio
##將/etc/passwd由/data/etc.cpio archive中還原

Example2:(Restore all files)

[root@nmc /data]# cpio -im < /data/etc.cpio
 
bullet cpio is designed to backup completely arbitrary set of files.
 
bullet Generally, cpio can pack data more efficiently than tar.
 
bullet On restore, cpio skips bad spots on the archive file, while tar just die.

 
bullet dump & restore
bullet dump 是UNIX作業系統中複雜度較高,且功能較為完整的備份工具,restore則是其相對的還原工具。(不同版本的dump名稱有些不同,例如AIX中為"backup"Solaris 中為ufsbackup/ufsrestoreLinux中則為dump/restore。就功能與用法而言則是大同小異。)
 
bullet dump selectively (according to the backup levels) backup all files within a filesystem (a disk partition).
dump 也可以用於備份單一目錄,但限於同一目錄下的所有檔案( 含所有其子目錄)。
 
bullet 對於完整file system備份而言,dump將備份等級分成10 levels(0~9)
L
evel 0 為Full Backup,其他levelbackup則會自動將上一次backup level低於本次等級備份時間之後異動的所有檔案,作為本次備份的標的,屬於incremental的方式。 (各個等級最近備份時間紀錄於/etc/dumpdates檔案中,如果此一檔案不存在,予以手動方式產生之)
 
bullet dump係針對整個file system備份至磁帶設計,當然,也可以用於單一目錄,也可將備份目的地指向硬碟中的某一檔案。
 
bullet 對於非整個File system的備份,dump僅能做Full Backup。(不管指定的backup等級為何)
 
bullet Command Format of dump:
dump options arguments filenames/directory
 
bullet full backup with dump(Examples)

[root@nmc /data]# dump 0uf  /data/home.dmp /home
or
[root@nmc /data]# dump 0uf /data/home.dmp  /dev/hda6
##options    0 --> Full backup (Level 0)
                  u --> 將備份時間紀錄於/etc/dumpdates (About level 0)
                  f  --> 指定備份目的地(若省略此參數,則將備份目的地指向磁帶機)
##本例子,將/dev/hda6備份成為單一檔案/data/home.dmp (file name don't care)
 
bullet Incremental backup with dump(Examples)

[root@nmc /data]# dump 1uf  /data/home.dmp /home
##本例子,將/dev/hda6上一次Full backup後異動的所有檔案備份成為單一檔案/data/home1.dmp (file name don't care)

 
bullet Command Format of restore:
restore options arguments [filenames/directory]
restoredump archive files中備份的檔案還原至指定的目錄
 
bullet restore files from dump archives with interactive mode
[root@nmc /data]# dump 0f /data/etc.
dmp /etc
##babckup /etc to a file "/data/etc.dmp
[root@nmc /data]#
restore -if etc.dmp
^^^^進入restoreinteractive mode
restore >
ls
.:
etc/

restore >
cd etc
restore >
add passwd
restore >
add hosts

^^^^將/etc/passwd 及 /etc/hosts列入還原清單
restore >
extract
^^^^還原/etc/passwd 及 /etc/hosts(還原至/data目錄之下)
You have not read any tapes 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 #:
1
set owner/mode for '.'? [yn]
n
restore >
quit
 
阅读(1048) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~