본문 바로가기

Linux

리눅스 백업 - dump & disk dump

리눅스 백업 관련 명령어

tar
- 로컬영역을 백업한다.
- 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
- 원본 폴더와 비교해 보면 같은 파일이 복원된 것을 알 수 있다.

'Linux' 카테고리의 다른 글

쉘프로그래밍 비교연산  (0) 2008.11.24
리눅스 커널 정보 변경  (0) 2008.11.20
리눅스 백업 - rsync  (0) 2008.11.17
리눅스 압축  (0) 2008.11.17
GRUB (GRand Unified Bootloader)  (0) 2008.11.17
부트로더  (0) 2008.11.17