리눅스 백업 관련 명령어
- 로컬영역을 백업한다.
- tar cvfpz [백업파일] [대상파일]
예)# tar cvfpz home.tar.gz /home - /home 디렉토리를 home.tar.gz로 압축하여 백업한다.
dump
- dump [option] [backup_name] [dump_file]
option
- 0~9 : 덤프레벨 0은 전체백업이고 나머지는 부분백업이다.
- f : 백업할 미디어 및 파일명 지정
예)
# dump -0f home_backup /home - /home디렉토리를 home_backup이란 이름으로 dump한다.
# dump -0f usr_backup /dev/sda5 - /dev/sda5 파티션을 usr_backup이란 이름으로 dump한다.
restore
- dump된 파일을 복구한다.
- restore [option] [dump_file]
option
-i : 대화식으로 복구 파일을 선택 후 복원
-f : 백업 파일명으로 지정
-r : 전체 복원
---------------------------------------------------------------------------------------------
예) dump 명령어를 이용해 /home 폴더를 백업해 보자.
# mkdir backup - 백업할 폴더를 생성한다.
# cd backup
# dump -0f home-backup /home - /home폴더를 home-backup 이름으로 dump한다.
DUMP: Date of this level 0 dump: Mon Nov 17 16:16:36 2008
DUMP: Dumping /dev/sda6 (/home) to home-backup
DUMP: Label: /home
DUMP: Writing 10 Kilobyte records
DUMP: mapping (Pass I) [regular files]
DUMP: mapping (Pass II) [directories]
DUMP: estimated 1890 blocks.
DUMP: Volume 1 started with block 1 at: Mon Nov 17 16:16:41 2008
DUMP: dumping (Pass III) [directories]
DUMP: dumping (Pass IV) [regular files]
DUMP: Closing home-backup
DUMP: Volume 1 completed at: Mon Nov 17 16:16:42 2008
DUMP: Volume 1 1820 blocks (1.78MB)
DUMP: Volume 1 took 0:00:01
DUMP: Volume 1 transfer rate: 1820 kB/s
DUMP: 1820 blocks (1.78MB) on 1 volume(s)
DUMP: finished in 1 seconds, throughput 1820 kBytes/sec
DUMP: Date of this level 0 dump: Mon Nov 17 16:16:36 2008
DUMP: Date this dump completed: Mon Nov 17 16:16:42 2008
DUMP: Average transfer rate: 1820 kB/s
DUMP: DUMP IS DONE
# ls -l
-rw-r--r-- 1 root root 1863680 11월 17 16:16 home-backup
# file home-backup
home-backup: new-fs dump file (little endian), This dump Mon Nov 17 16:16:36 2008, Previous dump Thu Jan 1 09:00:00 1970, Volume 1, Level zero, type: tape header, Label /home, Filesystem /home, Device /dev/sda6, Host server3, Flags 3
- dump를 통해 생성된 home-backup파일의 파일 종류를 알아본다.
# du -sh home-backup
1.8M home-backup
- dump를 통해 생성된 home-backup파일의 용량을 알아본다.
# restore -rf home-backup - dump인 home-backup파일의 전체를 복원한다.
# ls
aquota.user install.log.syslog ks.cfg lost+found protoss terran test1 test2 test3 zerg
home-backup restoresymtable
# ls /home
aquota.user install.log.syslog ks.cfg lost+found protoss terran test1 test2 test3 zerg
- 원본 폴더와 비교해 보면 같은 파일이 복원된 것을 알 수 있다.
---------------------------------------------------------------------------------------------
예) dump를 통해 백업된 파일을 필요한 파일 또는 폴더를 선택해서 복원해 보자.
# ls -l
-rw-r--r-- 1 root root 1863680 11월 17 16:16 home-backup
# restore -if home-backup - -i 옵션을 통해 필요한 파일 또는 폴더를 복원할 수 있다.
restore > help - dump -i 모드에서의 도움말을 확인 할 수 있다.
Available commands are:
ls [arg] - list directory
cd arg - change directory
pwd - print current directory
add [arg] - add `arg' to list of files to be extracted
delete [arg] - delete `arg' from list of files to be extracted
extract - extract requested files
setmodes - set modes of requested directories
quit - immediately exit program
what - list dump header information
verbose - toggle verbose flag (useful with "ls")
prompt - toggle the prompt display
help or `?' - print this list
If no `arg' is supplied, the current directory is used
restore > ls
aquota.user lost+found/ test1/ zerg/
install.log.syslog protoss/ test2/
ks.cfg terran/ test3/
restore > add test1
restore > add test2
restore > add test3 - 복원할 파일 또는 폴더를 선택한다.
restore > ls
aquota.user lost+found/ *test1/ zerg/
install.log.syslog protoss/ *test2/
ks.cfg terran/ *test3/ - 복원할 파일 또는 폴더에 '*'가 붙여져 있다.
restore > extract - dump파일에서 필요한 파일 또는 폴더를 푼다.
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] y
restore > quit - 복원이 끝났으면 dump -i 모드를 종료한다.
# ls -l
합계 1836
-rw-r--r-- 1 root root 1863680 11월 17 16:16 home-backup
drwx------ 18 test1 test1 4096 11월 17 10:09 test1
drwx------ 4 test2 test2 4096 11월 17 10:10 test2
drwx------ 3 test3 test3 4096 11월 12 09:33 test3
- 선택한 파일 또는 폴더가 복원 된 것을 확인 할 수 있다.
---------------------------------------------------------------------------------------------
dd (Disk Dump)
- dd if=[input_device] of=[output_device]
예) /dev/sda1 (= /boot) 파티션을 dd를 이용해 백업해 보자.
# fdisk /dev/sda - fdisk를 이용해 /dev/sda13 파티션을 새로 생성
# df -l
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 9920624 1125780 8282776 12% /
/dev/sda7 9920592 3505976 5902548 38% /usr
/dev/sda6 9920592 154972 9253552 2% /home
/dev/sda5 9920592 490128 8918396 6% /var
/dev/sda1 101086 11128 84739 12% /boot
tmpfs 512776 0 512776 0% /dev/shm
/dev/sda8 1929068 2880 1828196 1% /data1
# dd if=/dev/sda1 of=/dev/sda13
208782+0 records in
208782+0 records out
106896384 bytes (107 MB) copied, 17.1724 seconds, 6.2 MB/s
- /boot 파티션을 확인한 다음 dd 명령어를 이용해 디스크를 덤프시킨다.
# mkdir /boot-dd
# mount /dev/sda13 /boot-dd
- 마운트 할 폴더를 생성한 다음 dd로 생성한 /dev/sda13을 /boot-dd에 마운트 시킨다.
# ls /boot-dd
System.map-2.6.18-92.el5 grub lost+found symvers-2.6.18-92.el5.gz
config-2.6.18-92.el5 initrd-2.6.18-92.el5.img message vmlinuz-2.6.18-92.el5
# ls /boot
System.map-2.6.18-92.el5 grub lost+found symvers-2.6.18-92.el5.gz
config-2.6.18-92.el5 initrd-2.6.18-92.el5.img message vmlinuz-2.6.18-92.el5
- 원본 폴더와 비교해 보면 같은 파일이 복원된 것을 알 수 있다.
[출처] http://bban2.tistory.com/68
DD명령어 활용
기능 : 부트 플로피나 스왑파일을 만드는 특수한 복사를 위한 명령어이다.
사용법 : dd 옵션
of=file : 표준출력대신 지정한 파일에 작성한다.
if=file : 표준입력대신 지정한 파일에서 불러들인다.
ibs=size : 지정한 사이즈만큼 읽는다.
obs=size : 지정한 사이즈만큼 쓴다.
bs=size : 지정한 사이즈만큼 읽고 쓴다.
count=n : 입력블록의 ibs크기만큼 복사한다.
conv=ascii : EBCDIC->ASCII로 변환
conv=ebcdic : ASCII->EBCDIC로 변환
conv=ibm : ASCII코드호환을 EBCDIC코드로 변환
conv=swab : 입력되는 두 바이트의 순서를 바꾼다. 입력파일에서 짝이 맞지 않는 하나의 비트가 남으면 , 마지막 바이트는 단순히 복사된다.
활용
dd if=kernel-image of=/dev/fd0 bs=1440 -> 커널이미지(부팅디스크)를 fd0디스크에 1.4mb 사이즈로 복사함
[출처] http://blog.naver.com/koleekr7/100092813697
NAME
dd - 한 파일을 복사하는 동한 변환한다.
SYNOPSIS
dd [--help] [--version] [if=file] [of=file] [ibs=bytes] [obs=bytes]
[bs=bytes] [cbs=bytes] [skip=blocks] [seek=blocks] [count=blocks]
[conv={ascii,ebcdic,ibm,block,unblock,lcase,ucase,swab,noerror,notrunc,
sync}]
DESCRIPTION
이 문서는 더이상 최신 정보를 담고 있지않다. 그래서, 몇몇틀릴 경우 도
있고, 부족한 경우도 있을 것이다. 완전한매뉴얼을 원하면, Texinfo 문
서를 참조하기 바란다.
이 매뉴얼 페이지는 dd 명령의 GNU 버전에 대한 것이다. dd 명령은 지정
한 블럭크기만큼 파일을 복사하는데, 사용된다. 초기값으로는 표준 입력과
표준 출력을 사용한다. 또한 선택적으로 그 파일의 변환도 수행한다. (즉,
파일을 특정 크기로 나누는데, 주로 사용됩니다. - 옮긴이 말)
OPTIONS
사용될 수 있는 블럭 크지 지정의 문자들은 다음과 같다:
b=512, c=1, k=1024, w=2, xm=number m
--help 도움말을 보여주고 마친다.
--version
버전 정보를 보여주고 마친다.
if=file
표준 입력 대신에 지정한 file을 입력 대상으로 한다.
of=file
표준 출력 대신에 지정한 file을 출력 대상으로 한다. conv=notrunc
옵션을 사용하지 않는 한은, seek= 바이트 크기에 따라 ( seek= 크기
가 0아닌 한) 지정한 크기에 따라 출력 파일을 자른다.
ibs=bytes
한번에 bytes 바이트씩 읽는다.
obs=bytes
한번에 bytes 바이트씩 쓴다.
bs=bytes
한번에 bytes 바이트씩 읽고 쓴다. ibs, obs 값 무시.
cbs=bytes
한번에 bytes 바이트씩 변환한다.
skip=blocks
입력 시작에서 blocks 단위 만큼 ibs 크기를 건너띈다.(가령 skip=5,
ibs=10 이면, 처음 50바이트를건너띄어 작업을 계속한다.)
seek=blocks
출력 시작에서 blocks 단위 만큼 ibs 크기를 건너띈다.
count=blocks
입력의 blocks 의 ibs 크기만큼만 복사한다.
conv=conversion[,conversion…]
대상 파일로 복사할 때, conversion 으로 변환 한다.
Conversions:
ascii EBCDIC 코드를 ASCII 코드로.
ebcdic ASCIi 코드를 ebcdic 코드로.
ibm ASCII 코드를 alternate EBCDIC 코드로.
block cbs 단위로 변환 할 때 읽은 것 안에 있는 줄바꿈 문자들을공
백 문자로 바꾼다.
unblock
cbs 단위로 변환 할 때 읽은 것 안에 있는 공백 문자들을줄바
꿈 문자로 바꾼다.
lcase 대문자를 소문자로
ucase 소문자를 대문자로
swab 입력되는 두 바이트의 순서를 바꾼다. 유닉스의 dd 명 령 과
달 리, 이것은 읽혀질 짝이 맞지 않는 추가 바이트 하나가 생
겼을 때는그냥 그대로 작업한다. 즉, 입력 파일에서 짝이 맞
지 않는 하나의 바이트가 남으면, 마지막 바이트는 그냥 단순
히 복사된다. (이것의 순서가 바뀌지 않는한)
noerror
오류를 읽어도 계속 한다.
notrunc
출력 파일을 자르지 않는다.
sync ibs 블럭 크기와 obs 블럭 크기가 차이가 있을 경우, 그 여백
을 NULL문자로 채운다.