Showing posts with label CentOS 6.6 리눅스 관리. Show all posts
Showing posts with label CentOS 6.6 리눅스 관리. Show all posts

Friday, April 13, 2018

CentOS 6.6 리눅스 관리] 12. SWAP 메모리 관리


안녕하세요. 썬구루입니다. 이 게시물에서는 스왑(SWAP)에 대해 알아보도록 하겠습니다. 프로그램은 처리가 되기 위해 반드시 물리 메모리에 올라와야 합니다. 충분한 메모리가 있다면 상관없지만 리눅스 서버 시스템이 많은 프로세스를 돌리고 있어서 메모리가 부족하다면 어떻게 될까요?

프로세스는 우선순위라는 것을 가집니다. 우선순위에 따라 메모리, CPU 기타 하드웨어 자원에 대한 우선권을 가지는 것이죠. 만약 메모리를 100% 사용하고 있는데 우선순위가 높은 프로세스가 올라온다면 우선순위가 낮은 프로세스는 자신의 자원을 내놓아야 합니다. 물리 메모리에서 우선권이 높은 프로세스한테 엉덩이 까여서 나가떨어지는 것이죠. 만약 이 프로세스가 1시간 동안 어떠한 결과 처리를 위해 돌고 있었다면 그리고 자신의 메모리를 반환했다면 어떻게 되는 것일까요? 다시 1시간 동안 이 프로세스를 돌려야 할까요? 이때를 위해 디스크의 일정 공간(파티션 또는 볼륨)이나 파일이 임시 저장 공간으로 사용되는 것입니다. 마치 물리 메모리처럼 사용되는 것이죠. 디스크 일정 공간이나 파일을 마치 물리적인 메모리처럼 사용하는 이것을 우리는 SWAP 메모리라 합니다.

만약 4GB 메모리를 가지고 있는 서버다 그러면 8GB 정도의 SWAP 공간을 잡습니다. 하지만 32GB 메모리를 가지고 있는 서버라고 한다면 64GB SWAP 공간을 잡지 않습니다. 32GB나 48GB 정도의 SWAP 공간을 잡습니다.

이 게시물에서 우리는 SWAP 관리하는 명령에 대해 알아볼 것입니다.

■ SWAP 디바이스 확인

swapon -s 명령을 사용하거나 /proc/swaps 파일 내용을 확인하면 SWAP 디바이스를 확인할 수 있다.

[root@sunguru backup]# swapon -s
Filename    Type  Size Used Priority
/dev/sda2                               partition 4194300 0 -1
[root@sunguru backup]#
[root@sunguru backup]# more /proc/swaps
Filename    Type  Size Used Priority
/dev/sda2                               partition 4194300 0 -1
[root@sunguru backup]# 

■ SWAP 메모리 사용량 확인

free 명령 또는 top 명령을 사용하면 SWAP 메모리 용량 및 사용량을 알 수 있다. 하지만 SWAP 메모리가 사용되지 않고 있는 것을 확인할 수 있다.

[root@sunguru backup]# free
             total       used       free     shared    buffers     cached
Mem:       1915452     837588    1077864       4068      85948     384828
-/+ buffers/cache:     366812    1548640
Swap:      4194300          0    4194300
[root@sunguru backup]#
[root@sunguru backup]# top
top - 17:49:36 up 22:30,  2 users,  load average: 0.00, 0.00, 0.00
Tasks: 155 total,   1 running, 154 sleeping,   0 stopped,   0 zombie
Cpu(s):  1.0%us,  1.2%sy,  0.0%ni, 97.8%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   1915452k total,   838040k used,  1077412k free,    85980k buffers
Swap:  4194300k total,        0k used,  4194300k free,   384916k cached 

SWAP 메모리를 사용하도록 만들기 위해서는 프로세스를 많이 만들어 메모리로 올리면 된다. 이를 위해 아래 명령을 실행한다. 아래 명령은 실제 서버에 적용하지 않도록 한다. 왜냐하면 서버가 멈출 수도 있다.

[root@sunguru backup]# while true
> do
> sleep 300 &
> done
[root@sunguru backup]#

그리고 다른 터미널 창에서 top 명령을 실행하면 아래와 같이 SWAP 메모리가 사용되는 것을 확인할 수 있다.

top - 17:53:18 up 22:33,  3 users,  load average: 5.63, 2.33, 0.87
Tasks: 16134 total,   5 running, 16129 sleeping,   0 stopped,   0 zombie
Cpu(s):  1.4%us, 97.4%sy,  0.0%ni,  0.0%id,  0.1%wa,  0.2%hi,  0.9%si,  0.0%st
Mem:   1915452k total,  1848644k used,    66808k free,      736k buffers
Swap:  4194300k total,  1296572k used,  2897728k free,     9384k cached




■ SWAP 디바이스 또는 파일 설정

아래와 같이 /dev/sdd 디스크를 분할하여 /dev/sdd1 파티션을 생성한다. (LVM을 사용하여 볼륨을 생성하여도 된다.)

[root@sunguru ~]# fdisk /dev/sdd
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xc022ac12.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): +5G

Command (m for help): p

Disk /dev/sdd: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xc022ac12

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1         654     5253223+  83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@sunguru ~]# lsblk /dev/sdd
NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdd      8:48   0  10G  0 disk
└─sdd1   8:49   0   5G  0 part
[root@sunguru ~]# 

아래와 같이 dd 명령을 사용하여 SWAP 디바이스로 사용할 1GB 용량의 파일을 생성한다.

[root@sunguru ~]# dd if=/dev/zero of=/swapfile01 bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 5.33247 s, 201 MB/s
[root@sunguru ~]#
[root@sunguru ~]# ls -l /swapfile01
-rw-r--r--. 1 root root 1073741824 2016-07-11 18:07 /swapfile01
[root@sunguru ~]# 

■ SWAP 메모리 추가

아래와 같이 mkswap 명령을 사용하여 파티션, 볼륨 또는 파일을 SWAP 디바이스로 지정한다.

[root@sunguru ~]# mkswap /dev/sdd1
Setting up swapspace version 1, size = 5253216 KiB
no label, UUID=e133ad71-a4a3-442c-ad02-68f261e08ea4
[root@sunguru ~]#
[root@sunguru ~]# mkswap /swapfile01
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=abf4b853-6f35-460f-8eb8-4f2d5da89b61
[root@sunguru ~]# 

아래와 같이 swapon 명령을 실행하여 SWAP POOL에 SWAP 디바이스를 추가하여 SWAP 메모리 용량을 늘린다.

[root@sunguru ~]# swapon -s
Filename    Type  Size Used Priority
/dev/sda2                               partition 4194300 0 -1
[root@sunguru ~]#
[root@sunguru ~]# free
             total       used       free     shared    buffers     cached
Mem:       1915452    1677072     238380       3184      22708    1314224
-/+ buffers/cache:     340140    1575312
Swap:      4194300          0    4194300
[root@sunguru ~]#
[root@sunguru ~]# swapon /dev/sdd1
[root@sunguru ~]#
[root@sunguru ~]# swapon -s
Filename    Type  Size Used Priority
/dev/sda2                               partition 4194300 0 -1
/dev/sdd1                               partition 5253216 0 -2
[root@sunguru ~]#
[root@sunguru ~]# free
             total       used       free     shared    buffers     cached
Mem:       1915452    1680776     234676       3184      22736    1314240
-/+ buffers/cache:     343800    1571652
Swap:      9447516          0    9447516
[root@sunguru ~]#
[root@sunguru ~]# swapon /swapfile01
[root@sunguru ~]#
[root@sunguru ~]# swapon -s
Filename    Type  Size Used Priority
/dev/sda2                               partition 4194300 0 -1
/dev/sdd1                               partition 5253216 0 -2
/swapfile01                             file  1048572 0 -3
[root@sunguru ~]#
[root@sunguru ~]# free
             total       used       free     shared    buffers     cached
Mem:       1915452    1682528     232924       3184      22760    1314244
-/+ buffers/cache:     345524    1569928
Swap:     10496088          0   10496088
[root@sunguru ~]# 

/etc/fstab 파일에 내용을 추가한 후 리부팅을 후에도 추가한 SWAP 디바이스가 올라오는지 확인한다.

[root@sunguru ~]# vi /etc/fstab

/dev/sdd1               swap                    swap    defaults        0 0   <= 내용 추가
/swapfile01             swap                    swap    defaults        0 0   <= 내용 추가

[root@sunguru ~]#
[root@sunguru ~]# reboot
[root@sunguru ~]#
[root@sunguru ~]# swapon -s
Filename    Type  Size Used Priority
/dev/sda2                               partition 4194300 0 -1
/dev/sdd1                               partition 5253216 0 -2
/swapfile01                             file  1048572 0 -3
[root@sunguru ~]# free
             total       used       free     shared    buffers     cached
Mem:       1915452     529992    1385460       2336      21776     193936
-/+ buffers/cache:     314280    1601172
Swap:     10496088          0   10496088
[root@sunguru ~]# 

swapoff는 SWAP 풀에 있는 SWAP 디바이스를 제거하기 위해 사용하는 명령이다. 관련된 SWAP 디바이스가 사용되고 있지 않아야 제거를 할 수 있다.

[root@sunguru ~]# swapon -s
Filename    Type  Size Used Priority
/dev/sda2                               partition 4194300 0 -1
/dev/sdd1                               partition 5253216 0 -2
/swapfile01                             file  1048572 0 -3
[root@sunguru ~]#
[root@sunguru ~]# swapoff /swapfile01
[root@sunguru ~]#
[root@sunguru ~]# swapon -s
Filename    Type  Size Used Priority
/dev/sda2                               partition 4194300 0 -1
/dev/sdd1                               partition 5253216 0 -2
[root@sunguru ~]# 

여기까지 SWAP 관리하는 명령에 대해 알아보았습니다. SWAP은 물리적인 메모리가 아닙니다. 프로세스 정보를 임시적으로 저장하기 위해 사용되는 공간입니다. SWAP 메모리가 사용되고 SWAP I/O가 많이 발생한다면 물리적인 메모리가 부족하다는 뜻입니다. 그리고 서버의 정보처리 속도도 떨어지게 됩니다. 왜냐하면 SWAP I/O도 처리를 해야 되기 때문이죠. 빈번하게 SWAP 메모리를 사용한다면 물리적인 메모리를 늘려 줘야 서버의 정보처리가 원활하게 이루어집니다.

만약 물리적 메모리를 늘릴 수 없다고 하는 고객분들이 있으시다면 'SWAP 메모리는 물리적 메모리가 아닌 프로세스 정보 임시 저장 공간이다. 만약 SWAP I/O가 빈번하게 일어난다면 그 I/O를 처리하기 위해 CPU 자원이 사용될 것이고 I/O WAIT 등의 지연으로 인해 서버 성능은 현저하게 떨어질 것이다. 만약 물리적 메모리를 늘릴 수 없다면 서버 성능 저하는 감수해야 할 것이고 서비스 저하로 인한 문제가 반드시 일어날 것이다.' 라도 말씀해주시면 됩니다.







CentOS 6.6 리눅스 관리] 11.5 아카이브, 압축 및 백업/복구 - dump, restore


안녕하세요. 썬구루입니다. 이 게시물에서는 EXT 2/3/4 파일시스템 백업/복구 명령인 dump와 restore 명령에 대해 알아보도록 하겠습니다.

tar 명령은 디렉터리 또는 파일을 백업/복구하기 위해 사용되는 명령입니다. 특정 파일시스템을 단일 파일이나 테이프 드라이브 같은 장치에 백업 복구를 하기 위해서는 파일시스템 백업에 관련된 명령을 사용해야 하는 것이죠. CentOS 리눅스 버전 6까지 EXT 파일시스템을 주로 사용하는데 이 파일시스템을 백업/복구하기 위해서는 dump와 restore 명령을 사용하는 것이죠.

예전에  솔라리스 사용할 때는 UFS 파일시스템 백업/복구를 위해 ufsdump/ufsrestore 명령을 사용했었는데 명령 형식이 똑같더라고요. 개념도 똑같고... 그러니 금방 사용할 수 있었죠.. ^^ dump/restore 명령의 특징은 아래와 같습니다.

  ▶ EXT 2/3/4 파일시스템 백업을 하기 위해 사용
  ▶ 전체/증감 백업 가능
  ▶ 부분 복구 가능
  ▶ 멀티 볼륨 백업 가능 (여러 개의 테이프 미디어를 사용하여 파일시스템 백업 가능)

전체(Full) 백업과 증감(Incremental) 백업의 차이는 다음과 같습니다.

백업 종류
내 용
전체 백업
 파일시스템의 전체 파일을 백업하는 것을 말한다. (Full Backup)
차등 백업
 가장 최근 백업 이후 시점으로 변경된 파일만 백업하는 것을 말한다. (Differential Backup)
누적 백업
 가장 최근 전체 백업한 이후 시점으로 변경된 파일만 백업하는 것을 말한다. (Cumulative)

여기서는 mhVTL이 설치된 CentOS 6.4 리눅스 가상머신을 가지고 테스트를 하도록 하겠습니다.

■ dump 명령

dump 명령은 EXT 2/3/4 파일시스템을 백업하기 위해 사용되는 명령이다. 파일시스템 기반의 단일 파일로 또는 테이프 드라이브 같은 장치를 사용하여 백업을 할 수 있다.

1). 명령 형식

dump [옵션] -f DEVICENAME  FILESYSTEM

2). 옵션

옵 션
내 용
-0~9
 백업 레벨(Level)을 나타낸다. 0은 전체 백업을 1~9는 숫자 조합을 통해 차등 또는 누적 백업을 나타낸다. 여기에서는 일정한 규칙이 적용되는데 그것은 아래와 같다.

  '같은 수는 같은 수를 포함하고 작은 수는 큰 수를 포함한다.' 
-u
 /etc/dumpdates 파일에 파일시스템 백업 정보를 기록한다.
-s
 실제 백업은 하지 않고 백업 시 필요한 용량을 알아보기 위해 사용한다.
-f DEVICENAME
 tar 명령의 -f 옵션과 동일한다.

증감 백업의 기준은 전체 백업이다. 아래 그림을 보고 백업 레벨을 나타내는 번호가 어떻게 적용되는지 확인한다.

3). 예제

CentOS 6.4 리눅스 가상머신에 20GB 새 가상 디스크를 추가하여 인식시킨다.

[root@centos64 ~]# lspci | grep -i scsi
00:10.0 SCSI storage controller: LSI Logic / Symbios Logic 53c1030 PCI-X Fusion-MPT Dual Ultra320 SCSI (rev 01)
[root@centos64 ~]#
[root@centos64 ~]# find /sys/devices -name scan
/sys/devices/pci0000:00/0000:00:07.1/host1/scsi_host/host1/scan
/sys/devices/pci0000:00/0000:00:07.1/host2/scsi_host/host2/scan
/sys/devices/pci0000:00/0000:00:10.0/host0/scsi_host/host0/scan
/sys/devices/pseudo_0/adapter0/host3/scsi_host/host3/scan
[root@centos64 ~]#
[root@centos64 ~]# echo "- - -" > /sys/devices/pci0000:00/0000:00:10.0/host0/scsi_host/host0/scan
[root@centos64 ~]# lsblk
NAME                           MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                              8:0    0   20G  0 disk
├─sda1                           8:1    0  500M  0 part /boot
└─sda2                           8:2    0 19.5G  0 part
  ├─vg_centos64-lv_root (dm-0) 253:0    0 15.6G  0 lvm  /
  └─vg_centos64-lv_swap (dm-1) 253:1    0  3.9G  0 lvm  [SWAP]
sr0                             11:0    1  4.1G  0 rom  /media/CentOS_6.4_Final
sdb                              8:16   0   20G  0 disk 
[root@centos64 ~]# 

아래와 같이 LVM을 사용하여 5GB 용량의 볼륨을 생성. 그 위해 EXT4 파일시스템을 생성한 후 /data01 디렉터리에 마운트 시킨다.

[root@centos64 ~]# pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created
[root@centos64 ~]#
[root@centos64 ~]# vgcreate vg_db /dev/sdb
  Volume group "vg_db" successfully created
[root@centos64 ~]#
[root@centos64 ~]# lvcreate -L 5g -n data01 vg_db
  Logical volume "data01" created
[root@centos64 ~]#
[root@centos64 ~]# mkfs -t ext4 /dev/vg_db/data01
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
 32768, 98304, 163840, 229376, 294912, 819200, 884736
Writing inode tables: done                 
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@centos64 ~]#
[root@centos64 ~]# blkid /dev/vg_db/data01
/dev/vg_db/data01: UUID="cb71cfd6-5802-48f4-8469-0cab9716b2c4" TYPE="ext4"
[root@centos64 ~]#
[root@centos64 ~]# mkdir /data01
[root@centos64 ~]#
[root@centos64 ~]# mount /dev/vg_db/data01 /data01
[root@centos64 ~]#
[root@centos64 ~]# df -h /data01
Filesystem                                 Size  Used Avail Use% Mounted on
/dev/mapper/vg_db-data01         5.0G  138M  4.6G   3% /data01
[root@centos64 ~]#
[root@centos64 ~]# vi /etc/fstab

/dev/vg_db/data01 /data01   ext4 defaults 1 2   <== 내용 추가

[root@centos64 ~]#




아래와 같은 명령을 사용하여 /dev/st0 테이프 드라이브에 삽입되어 있는 테이프 미디어 내용을 삭제하여 초기화한다. 이 명령은 공 테이프처럼 사용하기 위해 실행하는 것이다.

 [root@centos64 ~]# mt -f /dev/st0 erase

dump와 restore 명령을 실행하기 위해 CentOS 6.4 DVD 1번 ISO 파일을 넣은 후 아래와 같이 관련 패키지를 설치한다.

[root@centos64 data01]# cd /media/CentOS_6.4_Final/Packages/
[root@centos64 Packages]#
[root@centos64 Packages]# rpm -ivh rmt-0.4-0.6.b42.el6.x86_64.rpm
warning: rmt-0.4-0.6.b42.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing...                ########################################### [100%]
   1:rmt                    ########################################### [100%]
[root@centos64 Packages]#
[root@centos64 Packages]# rpm -ivh dump-0.4-0.6.b42.el6.x86_64.rpm
warning: dump-0.4-0.6.b42.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing...                ########################################### [100%]
   1:dump                   ########################################### [100%]
[root@centos64 Packages]#
[root@centos64 Packages]# which dump
/sbin/dump
[root@centos64 Packages]# which restore
/sbin/restore
[root@centos64 Packages]#

아래와 같은 명령을 사용하여 /data01 파일시스템에 파일을 생성 후 파일시스템 전체 백업 및 증감 백업을 실행한다.

[root@centos64 Packages]# cd /data01
[root@centos64 data01]#
[root@centos64 data01]# touch file1 file2 file3
[root@centos64 data01]#
[root@centos64 data01]# ls -l
total 16
-rw-r--r--. 1 root root     0 Jul 11 23:23 file1
-rw-r--r--. 1 root root     0 Jul 11 23:23 file2
-rw-r--r--. 1 root root     0 Jul 11 23:23 file3
drwx------. 2 root root 16384 Jul 11 23:09 lost+found
[root@centos64 data01]#
[root@centos64 data01]# dump -0uf /dev/nst0 /data01
  DUMP: Date of this level 0 dump: Mon Jul 11 23:23:57 2016
  DUMP: Dumping /dev/mapper/vg_db-data01 (/data01) to /dev/nst0
  DUMP: Label: none
  DUMP: Writing 10 Kilobyte records
  DUMP: mapping (Pass I) [regular files]
  DUMP: mapping (Pass II) [directories]
  DUMP: estimated 110 blocks.
  DUMP: Volume 1 started with block 1 at: Mon Jul 11 23:23:57 2016
  DUMP: dumping (Pass III) [directories]
  DUMP: dumping (Pass IV) [regular files]
  DUMP: Closing /dev/nst0
  DUMP: Volume 1 completed at: Mon Jul 11 23:23:57 2016
  DUMP: Volume 1 100 blocks (0.10MB)
  DUMP: 100 blocks (0.10MB) on 1 volume(s)
  DUMP: finished in less than a second
  DUMP: Date of this level 0 dump: Mon Jul 11 23:23:57 2016
  DUMP: Date this dump completed:  Mon Jul 11 23:23:57 2016
  DUMP: Average transfer rate: 0 kB/s
  DUMP: DUMP IS DONE
[root@centos64 data01]#
[root@centos64 data01]# touch file3 file4
[root@centos64 data01]#
[root@centos64 data01]# dump -1uf /dev/nst0 /data01
  DUMP: Date of this level 1 dump: Mon Jul 11 23:24:42 2016
  DUMP: Date of last level 0 dump: Mon Jul 11 23:23:57 2016
  DUMP: Dumping /dev/mapper/vg_db-data01 (/data01) to /dev/nst0
  DUMP: Label: none
  DUMP: Writing 10 Kilobyte records
  DUMP: mapping (Pass I) [regular files]
  DUMP: mapping (Pass II) [directories]
  DUMP: estimated 100 blocks.
  DUMP: Volume 1 started with block 1 at: Mon Jul 11 23:24:42 2016
  DUMP: dumping (Pass III) [directories]
  DUMP: dumping (Pass IV) [regular files]
  DUMP: Closing /dev/nst0
  DUMP: Volume 1 completed at: Mon Jul 11 23:24:42 2016
  DUMP: Volume 1 100 blocks (0.10MB)
  DUMP: 100 blocks (0.10MB) on 1 volume(s)
  DUMP: finished in less than a second
  DUMP: Date of this level 1 dump: Mon Jul 11 23:24:42 2016
  DUMP: Date this dump completed:  Mon Jul 11 23:24:42 2016
  DUMP: Average transfer rate: 0 kB/s
  DUMP: DUMP IS DONE
[root@centos64 data01]#
[root@centos64 data01]# touch file5
[root@centos64 data01]#
[root@centos64 data01]# ls -l
total 16
-rw-r--r--. 1 root root     0 Jul 11 23:23 file1
-rw-r--r--. 1 root root     0 Jul 11 23:23 file2
-rw-r--r--. 1 root root     0 Jul 11 23:24 file3
-rw-r--r--. 1 root root     0 Jul 11 23:24 file4
-rw-r--r--. 1 root root     0 Jul 11 23:24 file5
drwx------. 2 root root 16384 Jul 11 23:09 lost+found
[root@centos64 data01]#
[root@centos64 data01]# dump -2uf /dev/nst0 /data01
  DUMP: Date of this level 2 dump: Mon Jul 11 23:25:09 2016
  DUMP: Date of last level 1 dump: Mon Jul 11 23:24:42 2016
  DUMP: Dumping /dev/mapper/vg_db-data01 (/data01) to /dev/nst0
  DUMP: Label: none
  DUMP: Writing 10 Kilobyte records
  DUMP: mapping (Pass I) [regular files]
  DUMP: mapping (Pass II) [directories]
  DUMP: estimated 99 blocks.
  DUMP: Volume 1 started with block 1 at: Mon Jul 11 23:25:09 2016
  DUMP: dumping (Pass III) [directories]
  DUMP: dumping (Pass IV) [regular files]
  DUMP: Closing /dev/nst0
  DUMP: Volume 1 completed at: Mon Jul 11 23:25:09 2016
  DUMP: Volume 1 100 blocks (0.10MB)
  DUMP: 100 blocks (0.10MB) on 1 volume(s)
  DUMP: finished in less than a second
  DUMP: Date of this level 2 dump: Mon Jul 11 23:25:09 2016
  DUMP: Date this dump completed:  Mon Jul 11 23:25:09 2016
  DUMP: Average transfer rate: 0 kB/s
  DUMP: DUMP IS DONE
[root@centos64 data01]#

명령을 실행한 내용은 아래와 같다.

1. /data01로 이동
2. touch 명령으로 file1, file2, fil3 파일 생성 후 dump 명령을 사용하여 /dev/st0 테이프 디바이스로 전체 백업 실행
   -> file1, file2, file3, lost_found 백업
3. touch 명령으로 file3 수정시간 변경, file4 파일 생성 후 증감 백업 (Level 1) 실행
   -> file3, file4 백업
4. touch 명령으로 file5 파일 생성 후 증감 백업 (Level 1) 실행
   -> file5 백업

아래는 /etc/dumpfiles 파일에 저장된 파일시스템 백업 정보 내용이다. 줄의 내용은 '파일시스템 백업 레벨 백업 시간'이다.

[root@centos64 data01]# more /etc/dumpdates
/dev/mapper/vg_db-data01 0 Mon Jul 11 23:23:57 2016 +0900
/dev/mapper/vg_db-data01 1 Mon Jul 11 23:24:42 2016 +0900
/dev/mapper/vg_db-data01 2 Mon Jul 11 23:25:09 2016 +0900
[root@centos64 data01]#  




■ restore 명령

dump 명령으로 백업한 것을 복구하기 위해 사용되는 명령이다.

1). 명령 형식

restore [옵션] -f DEVICENAME

2). 옵션

옵 션
내 용
-t
 복구는 하지 않고 백업된 파일 리스트 정보를 확인하기 위해 사용한다.
-r
 전체 복구를 하기 위해 사용한다.
-i
 상호 대화형 모드에서 파일 복구를 하기 위해 사용한다. (Interactive mode)
-x
 부분 복구를 하기 위해 사용한다.
-v
 Verbose mode
-f DEVICENAME
 tar 명령의 -f 옵션과 동일한다.

3). 예제

아래 명령을 실행하여 /dev/st0 테이프 디바이스에 있는 테이프 미디어를 처음으로 되감는다.

 [root@centos64 data01]# mt -f /dev/st0 rewind

테이프 미디어에는 3개의 백업 이미지 즉 서브 볼륨(Sub Volume)이 존재한다. 왜냐하면 3번을 백업했기 때문이다. 아래는 첫 번째 백업 이미지를 확인하고 /data01/test1 디렉터리에 복구를 하였다.

[root@centos64 data01]# mkdir test1 test2 test3
[root@centos64 data01]#
[root@centos64 data01]# cd test1
[root@centos64 test1]#
[root@centos64 test1]# restore -tvf /dev/st0
Verify tape and initialize maps
Input is from a local tape
Tape block size is 10
Dump   date: Mon Jul 11 23:23:57 2016
Dumped from: the epoch
Level 0 dump of /data01 on centos64:/dev/mapper/vg_db-data01
Label: none
Extract directories from tape
Initialize symbol table.
dir          2 .
dir         11 ./lost+found
leaf        12 ./file1
leaf        13 ./file2
leaf        14 ./file3
[root@centos64 test1]# ls
file1  file2  file3  lost+found  restoresymtable
[root@centos64 test1]#
[root@centos64 test1]# restore -rvf /dev/nst0
Verify tape and initialize maps
Input is from a local tape
Tape block size is 10
Dump   date: Mon Jul 11 23:23:57 2016
Dumped from: the epoch
Level 0 dump of /data01 on centos64:/dev/mapper/vg_db-data01
Label: none
Begin level 0 restore
Initialize symbol table.
Extract directories from tape
Calculate extraction list.
restore: ./lost+found: File exists
Extract new leaves.
Check pointing the restore
extract file ./file1
extract file ./file2
extract file ./file3
Add links
Set directory mode, owner, and times.
Check the symbol table.
Check pointing the restore
[root@centos64 test1]#
[root@centos64 test1]# ls
file1  file2  file3  lost+found  restoresymtable
[root@centos64 test1]# 

아래는 테이프를 앞으로 되돌리고 구간 이동을 한 다음 restore 명령을 실행하여 file3, file4를 복구하는 것을 보여준다.

[root@centos64 test1]# mt -f /dev/st0 rewind
[root@centos64 test1]#
[root@centos64 test1]# mt -f /dev/nst0 fsf 1
[root@centos64 test1]#
[root@centos64 test1]# restore -rvf /dev/nst0
Verify tape and initialize maps
Input is from a local tape
Tape block size is 10
Dump   date: Mon Jul 11 23:24:42 2016
Dumped from: Mon Jul 11 23:23:57 2016
Level 1 dump of /data01 on centos64:/dev/mapper/vg_db-data01
Label: none
Begin incremental restore
Initialize symbol table.
Extract directories from tape
Mark entries to be removed.
Calculate node updates.
Find unreferenced names.
Remove old nodes (directories).
Extract new leaves.
Check pointing the restore
Remove leaf ./file3
extract file ./file3
extract file ./file4
Add links
Set directory mode, owner, and times.
Check the symbol table.
Check pointing the restore
[root@centos64 test1]#
[root@centos64 test1]# ls
file1  file2  file3  file4  lost+found  restoresymtable
[root@centos64 test1]#

아래는 테이프를 앞으로 되돌리고 구간 이동을 한 다음 restore 명령에 -x 옵션을 사용하여 file5를 복구하는 것을 보여준다.

[root@centos64 test1]# mt -f /dev/st0 rewind
[root@centos64 test1]# mt -f /dev/nst0 fsf 2
[root@centos64 test1]#
[root@centos64 test1]# restore -xvf /dev/st0 ./file5
Verify tape and initialize maps
Input is from a local tape
Tape block size is 10
Dump   date: Mon Jul 11 23:25:09 2016
Dumped from: Mon Jul 11 23:24:42 2016
Level 2 dump of /data01 on centos64:/dev/mapper/vg_db-data01
Label: none
Extract directories from tape
Initialize symbol table.
Extract requested files
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
extract file ./file5
Add links
Set directory mode, owner, and times.
set owner/mode for '.'? [yn] y
[root@centos64 test1]#
[root@centos64 test1]# ls
file1  file2  file3  file4  file5  lost+found  restoresymtable
[root@centos64 test1]# 


여기까지 dump와 restore 명령을 사용하여 EXT 파일시스템 백업 및 파일 복구에 대해 알아보았습니다. 다음 게시물에서는 SWAP 메모리에 대해 알아보도록 하겠습니다.






CentOS 6.6 리눅스 관리] 11.4 아카이브, 압축 및 백업/복구 - gzip, bzip2 명령


안녕하세요. 썬구루입니다. 이 게시물에서는 압축 명령인 comnpress, gzip과 bzip2 명령에 대해 알아보도록 하겠습니다. 만약 서비스에는 사용되지 않지만 파일들을 서버에 장기간 보관해야 한다면 어떻게 해야 할까요? 또는 파일을 네트워크를 통해 다른 컴퓨터로 전송해야 한다면  어떻게 할까요?

이때는 파일 압축 명령을 사용하여 파일 크기를 줄여서 보관한다거나 전송하면 됩니다. 압축하는 의미는 누구나 잘 알고 있습니다. 예를 들어 재활용 캔이 있는데 이것을 보통 그냥 버리죠. 일정한 크기가 있기 때문에 그냥 회수를 해서 재활용센터에 가져가면 얼마 가지고 가지 못할 것입니다. 만약 이것들을 발로 밟거나 압축기로 누르면 부피가 많이 줄어들어 한 번에 많은 양의 재활용 캔을 가져갈 수 있을 것입니다.

파일도 마찬가지입니다. 일정 크기의 파일들이 있는데 이것을 장기간 보관하면 그 크기 그대로 유지되니까 압축 명령을 사용하여 크기를 줄이고 그 줄어든 용량만큼 다른 파일들을 위해 활용할 수 있는 것이죠. 여러 파일들을 압축하려 한다면 tar로 묶어서 만들어진 단일 파일을 압축하는 것이고요. 파일을 전송할 때에도 압축된 파일을 전송하면 크기가 줄어든 상태이기 때문에 전송시간이 단축되는 것이죠.

CentOS 6.6에서는 파일을 압축하기 위해 gzip, bzip2, compress를 사용합니다. 하지만 compress는 별도로 패키지를 설치해줘야 사용할 수 있습니다.

[root@sunguru backup]# cd /media/CentOS_6.6_Final/Packages/
[root@sunguru Packages]# ls | grep compress
ncompress-4.2.4-54.el6_2.1.x86_64.rpm
[root@sunguru Packages]# rpm -qa | grep ncompress
[root@sunguru Packages]# rpm -ivh ncompress-4.2.4-54.el6_2.1.x86_64.rpm
warning: ncompress-4.2.4-54.el6_2.1.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing...                ########################################### [100%]
   1:ncompress              ########################################### [100%]
[root@sunguru Packages]# which compress
/usr/bin/compress
[root@sunguru Packages]# 

■ compress & uncompress 명령

compress는 파일 압축을 하기 위해 사용되는 명령이고 uncompress는 이를 풀기 위해 사용하는 명령이다. 이 명령으로 압축 시 파일 확장자. Z가 파일 이름에 따라붙는다.

[root@sunguru /]# cd /backup
[root@sunguru backup]# ls -l
total 48936
drwxr-xr-x. 114 root root    12288 Jul 11 03:31 etc
-rw-r--r--.   1 root root 31631360 Jul 11 01:08 etc_2016071001.tar
-rw-r--r--.   1 root root  8594496 Jul 11 01:08 etc_2016071001.tar.bz2
-rw-r--r--.   1 root root  9848450 Jul 11 01:09 etc_2016071001.tar.gz
drwx------.   2 root root    16384 Jul 11 01:22 lost+found
[root@sunguru backup]# mkdir BAK
[root@sunguru backup]# mv etc_2016071001.tar.bz2 etc_2016071001.tar.gz BAK
[root@sunguru backup]#
[root@sunguru backup]# ls -l
total 30924
drwxr-xr-x.   2 root root     4096 Jul 11 13:23 BAK
drwxr-xr-x. 114 root root    12288 Jul 11 03:31 etc
-rw-r--r--.   1 root root 31631360 Jul 11 01:08 etc_2016071001.tar
drwx------.   2 root root    16384 Jul 11 01:22 lost+found
[root@sunguru backup]#
[root@sunguru backup]# compress etc_2016071001.tar
[root@sunguru backup]# 
[root@sunguru backup]# ls -l
total 15692
drwxr-xr-x.   2 root root     4096 Jul 11 13:23 BAK
drwxr-xr-x. 114 root root    12288 Jul 11 03:31 etc
-rw-r--r--.   1 root root 16035765 Jul 11 01:08 etc_2016071001.tar.Z
drwx------.   2 root root    16384 Jul 11 01:22 lost+found
[root@sunguru backup]#
[root@sunguru backup]# uncompress etc_2016071001.tar.Z
[root@sunguru backup]#
[root@sunguru backup]#
[root@sunguru backup]# ls -l
total 30924
drwxr-xr-x.   2 root root     4096 Jul 11 13:23 BAK
drwxr-xr-x. 114 root root    12288 Jul 11 03:31 etc
-rw-r--r--.   1 root root 31631360 Jul 11 01:08 etc_2016071001.tar
drwx------.   2 root root    16384 Jul 11 01:22 lost+found
[root@sunguru backup]# 

■ gzip & gunzip 명령

gzip는 파일 압축을 하기 위해 사용되는 명령이고 gunzip는 이를 풀기 위해 사용하는 명령이다. 이 명령으로 압축 시 파일 확장자. gz가 파일 이름에 따라붙는다. compress 명령보다 압축률이 뛰어나다. gzip 명령의 -d 옵션을 사용해서 압축을 풀 수도 있다.

[root@sunguru backup]# ls -l
total 30924
drwxr-xr-x.   2 root root     4096 Jul 11 13:23 BAK
drwxr-xr-x. 114 root root    12288 Jul 11 03:31 etc
-rw-r--r--.   1 root root 31631360 Jul 11 01:08 etc_2016071001.tar
drwx------.   2 root root    16384 Jul 11 01:22 lost+found
[root@sunguru backup]#
[root@sunguru backup]# gzip etc_2016071001.tar
[root@sunguru backup]#
[root@sunguru backup]# ls -l
total 9652
drwxr-xr-x.   2 root root    4096 Jul 11 13:23 BAK
drwxr-xr-x. 114 root root   12288 Jul 11 03:31 etc
-rw-r--r--.   1 root root 9848469 Jul 11 01:08 etc_2016071001.tar.gz
drwx------.   2 root root   16384 Jul 11 01:22 lost+found
[root@sunguru backup]#
[root@sunguru backup]# gunzip etc_2016071001.tar.gz
[root@sunguru backup]#
[root@sunguru backup]# ls -l
total 30924
drwxr-xr-x.   2 root root     4096 Jul 11 13:23 BAK
drwxr-xr-x. 114 root root    12288 Jul 11 03:31 etc
-rw-r--r--.   1 root root 31631360 Jul 11 01:08 etc_2016071001.tar
drwx------.   2 root root    16384 Jul 11 01:22 lost+found
[root@sunguru backup]#
[root@sunguru backup]# gzip etc_2016071001.tar
[root@sunguru backup]#
[root@sunguru backup]# ls -l *.gz
-rw-r--r--. 1 root root 9848469 Jul 11 01:08 etc_2016071001.tar.gz
[root@sunguru backup]#
[root@sunguru backup]# gzip -d etc_2016071001.tar.gz
[root@sunguru backup]#
[root@sunguru backup]# ls -l
total 30924
drwxr-xr-x.   2 root root     4096 Jul 11 13:23 BAK
drwxr-xr-x. 114 root root    12288 Jul 11 03:31 etc
-rw-r--r--.   1 root root 31631360 Jul 11 01:08 etc_2016071001.tar
drwx------.   2 root root    16384 Jul 11 01:22 lost+found
[root@sunguru backup]#​

■ bzip2 & bunzip2 명령

bzip2 는 파일 압축을 하기 위해 사용되는 명령이고 bunzip2는 이를 풀기 위해 사용하는 명령이다. 이 명령으로 압축 시 파일 확장자 .bz2가 파일 이름에 붙는다. gzip 명령보다 압축률이 뛰어나다. bzip2 명령의 -d 옵션을 사용해서 압축을 풀 수도 있다.

[root@sunguru backup]# ls -l
total 30924
drwxr-xr-x.   2 root root     4096 Jul 11 13:23 BAK
drwxr-xr-x. 114 root root    12288 Jul 11 03:31 etc
-rw-r--r--.   1 root root 31631360 Jul 11 01:08 etc_2016071001.tar
drwx------.   2 root root    16384 Jul 11 01:22 lost+found
[root@sunguru backup]#
[root@sunguru backup]# bzip2 etc_2016071001.tar
[root@sunguru backup]#
[root@sunguru backup]# ls -l
total 8428
drwxr-xr-x.   2 root root    4096 Jul 11 13:23 BAK
drwxr-xr-x. 114 root root   12288 Jul 11 03:31 etc
-rw-r--r--.   1 root root 8594496 Jul 11 01:08 etc_2016071001.tar.bz2
drwx------.   2 root root   16384 Jul 11 01:22 lost+found
[root@sunguru backup]#
[root@sunguru backup]# bunzip2 etc_2016071001.tar.bz2
[root@sunguru backup]#
[root@sunguru backup]# ls -l
total 30924
drwxr-xr-x.   2 root root     4096 Jul 11 13:23 BAK
drwxr-xr-x. 114 root root    12288 Jul 11 03:31 etc
-rw-r--r--.   1 root root 31631360 Jul 11 01:08 etc_2016071001.tar
drwx------.   2 root root    16384 Jul 11 01:22 lost+found
[root@sunguru backup]#
[root@sunguru backup]# bzip2 etc_2016071001.tar
[root@sunguru backup]#
[root@sunguru backup]# ls -l *.bz2
-rw-r--r--. 1 root root 8594496 Jul 11 01:08 etc_2016071001.tar.bz2
[root@sunguru backup]#
[root@sunguru backup]# bzip2 -d etc_2016071001.tar.bz2
[root@sunguru backup]#
[root@sunguru backup]# ls -l
total 30924
drwxr-xr-x.   2 root root     4096 Jul 11 13:23 BAK
drwxr-xr-x. 114 root root    12288 Jul 11 03:31 etc
-rw-r--r--.   1 root root 31631360 Jul 11 01:08 etc_2016071001.tar
drwx------.   2 root root    16384 Jul 11 01:22 lost+found
[root@sunguru backup]#

실제 리눅스 또는 유닉스 소프트웨어 파일이 배포될 때도 gzip 또는 bzip2 명령으로 압축하여 배포하는 경우가 많습니다. 명령이 어렵지 않으니 이건 꼭 기억하시길~!! ^^

다음 게시물에서는 EXT 파일시스템을 백업/복구하기 위한 dump와 restore 명령에 대해 알아보도록 하겠습니다.






CentOS 6.6 리눅스 관리] 11.3 아카이브, 압축 및 백업/복구 - tar, mt 명령


안녕하세요. 썬구루입니다. 이제 아카이브 명령인 tar와 테이프 매체 제어 명령인 mt 명령에 대해 알아보도록 하겠습니다. 백업이란 특정 시점에 원본에 대한 사본을 만드는 것이고 복구는 특정 시점에 백업한 사본을 가지고 데이터를 복원하는 것이라고 앞 게시물에서 언급하였었습니다.

만약 여러분들이 만든 문서를 제출하기 위해 컴퓨터에 작성한 파일을 USB 플래시 메모리로 복사를 하였다면 그것이 바로 백업입니다. 그리고 사본을 제출하려 하는 것이죠. 그런데 만약 여러분들이 만든 원본의 데이터가 실수로 인해 삭제가 되었다면 어떻게 할 수 있을까요? 이미 제출한 USB 메모리를 회수하여 다른 USB 메모리 복사한 후 사본은 제출하고 다른 사본을 집으로 가져와 컴퓨터에 복사한다면 그것이 바로 복구입니다.

만약 그 사이에 갱신된 내용이 있었는데 원본 파일이 삭제되었다면 갱신된 내용들은 유실이 되는 것이죠. 왜냐하면 사본을 만든 그 시점까지에 대한 정보만 있을 테니까요. 백업을 하는 방법은 다양합니다. 그중 이 게시물에서 우리는 tar 명령을 가지고 백업/복구를 해보려 하는 것이죠.

tar는 tape archive의 약자입니다. 테이프에 특정 파일들을 아카이빙 하기 위해 사용되었던 명령이죠. 그럼 아카이브(Archive)란 무엇이냐?
아카이브란 백업을 위해 특정 시간에 함께 패키지한 파일들의 집합을 뜻합니다. 다르게 말하면 백업을 위해 특정 파일들을 묶는다는 것이죠. 그럼 어디에 묶어서 보관하느냐?

  ▶ 파일시스템 위의 단일 파일
  ▶ 테이프 미디어(Tape Media. DDS, SDLT, DLT, LTO 등)
  ▶ USB 플래시 메모리, DVD 등

위와 같은 매체에 보관할 수 있습니다.

간혹 tar를 압축 명령이라고 하는 분들이 있는데 tar는 단순히 파일들을 묶어 저장하거나 추출하는 기능을 위해 사용하지 압축 기능은 없습니다. 그럼 tar를 뭐라 부르는데요? 아카이브 명령!!! 압축된다던데요? 그것은 tar의 옵션을 사용하여 다른 압축 명령을 호출하여 사용하는 것입니다. mt는 뭔데요.? mt는 Magetic Tape의 약자로 테이프 드라이브에 삽입된 테이프 미디어를 제어하기 위해 사용되는 명령입니다. 보통 단일 서버 시스템 데이터 백업을 하기 위해 내장 또는 외장형 단일 드라이브를 사용합니다. 서버가 유닉스 또는 리눅스 운영체제를 사용한다면 드라이브 안에 있는 테이프 미디어를 제어하기 위해 사용하는 명령이 mt 명령입니다.

■ tar 명령

파일이나 디렉터리를 특정 시점에 단일 파일 또는 테이프 같은 다른 저장 매체에 백업 또는 복구(추출) 하기 위해 사용되는 명령이다.

1). 명령 형식

tar [옵션] [파일...]

2). 옵션

옵 션
내 용
-c
 tar 아카이브를 생성하기 위해 사용되는 옵션이다.
-t
 아카이브에 있는 파일 리스트를 출력하기 위해 사용되는 옵션이다.
-x
 아카이브에 있는 파일을 추출하기 위해 사용되는 옵션이다.
-v
 Verbose mode
-f DEVICENAME
 디바이스를 명시하기 위해 사용되는 옵션이다. 디바이스 이름 대신 파일 이름이 올 수도 있다.
-j
 bzip2를 통해 아카이브를 한다.
-z
 gzip을 통해 아카이브를 필터한다.
-Z
 compress를 통해 아카이브를 필터한다.
-C DIRECTORY
 특정 디렉터리에 풀기 위해 사용하는 옵션이다.

3). 예제

 ▶ tar 백업

이전에 만들었던 /dev/sdc1에 생성한 파일시스템을 /backup 디렉터리를 생성한 후 마운트한다. 그리고 /etc 디렉터리에 있는 파일들을 tar 명령을 사용하여 /backup 디렉터리에 단일 파일로 아카이브 하는 것을 보여준다. -j 와 -z 옵션을 사용하여 tar 아카이브를 한 파일 용량을 자세히 확인해보자. 그리고 file 명령으로 파일 유형을 확인해보자.

[root@sunguru ~]# blkid
/dev/sda3: UUID="047dc93f-6363-4570-a7b5-1937a6534afa" TYPE="ext4"
/dev/sda1: UUID="b7618935-2a1e-4f2a-ad9f-167a96b8e935" TYPE="ext4"
/dev/sda2: UUID="1b4804f6-b38b-4484-928d-73f04f327afb" TYPE="swap"
/dev/sdb1: UUID="b380e123-e1ee-4ae2-8ae2-55827b5bae91" TYPE="ext4"
/dev/sdc1: UUID="6b5eddb7-6373-42fc-9d74-dc95507d4280" SEC_TYPE="ext2" TYPE="ext3"
/dev/sdc2: UUID="000558d2-4c63-417e-83aa-ae38cef22887" TYPE="ext4"
/dev/sr0: LABEL="CentOS_6.6_Final" TYPE="iso9660"
[root@sunguru ~]#
[root@sunguru ~]# df -hF ext4
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        16G  2.8G   12G  19% /
/dev/sda1       190M   32M  149M  18% /boot
/dev/sdc2       2.2T   73M  2.0T   1% /data02
[root@sunguru ~]#
[root@sunguru ~]# mkdir /backup
[root@sunguru ~]# mount /dev/sdb1 /backup
[root@sunguru ~]#
[root@sunguru ~]# df -h /backup
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdb1       4.9G   11M  4.6G   1% /backup
[root@sunguru ~]#
[root@sunguru ~]# cd /etc
[root@sunguru etc]#
[root@sunguru etc]# tar -cf /backup/etc_2016071001.tar ./*
[root@sunguru etc]# tar -cjf /backup/etc_2016071001.tar.bz2 ./*
[root@sunguru etc]# tar -czf /backup/etc_2016071001.tar.gz ./*
[root@sunguru etc]#
[root@sunguru etc]#
[root@sunguru etc]# ls -l /backup
total 48924
-rw-r--r--. 1 root root 31631360 Jul 11 01:08 etc_2016071001.tar
-rw-r--r--. 1 root root  8594496 Jul 11 01:08 etc_2016071001.tar.bz2
-rw-r--r--. 1 root root  9848450 Jul 11 01:09 etc_2016071001.tar.gz
drwx------. 2 root root    16384 Jun 28 18:01 lost+found
[root@sunguru etc]#
[root@sunguru etc]# file /backup/*
/backup/etc_2016071001.tar:     POSIX tar archive (GNU)
/backup/etc_2016071001.tar.bz2: bzip2 compressed data, block size = 900k
/backup/etc_2016071001.tar.gz:  gzip compressed data, from Unix, last modified: Mon Jul 11 01:09:00 2016
/backup/lost+found:             directory
[root@sunguru etc]# 

▶ tar 아카이브 파일 리스트 확인

tar 아카이브 파일에서 아카이브된 파일 리스트를 확인하기 위해 -t 옵션을 사용할 수 있다. 이때 -v 옵션도 같이 사용한다.

[root@sunguru backup]# ls
etc_2016071001.tar  etc_2016071001.tar.bz2  etc_2016071001.tar.gz  lost+found
[root@sunguru backup]#
[root@sunguru backup]#
[root@sunguru backup]# tar -tvf etc_2016071001.tar | head
drwxr-xr-x root/root         0 2016-05-27 02:46 ./ConsoleKit/
drwxr-xr-x root/root         0 2010-11-11 07:09 ./ConsoleKit/run-seat.d/
drwxr-xr-x root/root         0 2010-11-11 07:09 ./ConsoleKit/run-session.d/
drwxr-xr-x root/root         0 2016-05-27 02:46 ./ConsoleKit/seats.d/
-rw-r--r-- root/root        64 2010-11-11 07:09 ./ConsoleKit/seats.d/00-primary.seat
-rw-r--r-- root/root      4439 2014-07-17 00:02 ./DIR_COLORS
-rw-r--r-- root/root      5139 2014-07-17 00:02 ./DIR_COLORS.256color
-rw-r--r-- root/root      4113 2014-07-17 00:02 ./DIR_COLORS.lightbgcolor
drwxr-xr-x root/root         0 2016-05-27 02:48 ./NetworkManager/
drwxr-xr-x root/root         0 2014-10-15 19:26 ./NetworkManager/dispatcher.d/
[root@sunguru backup]# 




▶ tar 복구(추출)

etc_2016071001.tar 파일에 아카이브되어 있는 모든 파일들을 /backup/etc 디렉터리에 풀기 위해 아래 명령을 사용한다.

[root@sunguru backup]# pwd
/backup
[root@sunguru backup]# ls
etc_2016071001.tar  etc_2016071001.tar.bz2  etc_2016071001.tar.gz  lost+found
[root@sunguru backup]#
[root@sunguru backup]# mkdir etc
[root@sunguru backup]#
[root@sunguru backup]# tar -xf etc_2016071001.tar -C /backup/etc 2> /dev/null
[root@sunguru backup]#
[root@sunguru backup]# ls -Rl etc/ | wc -l
3100
[root@sunguru backup]# 

특정 파일만 추출하기 위해 복구할 파일 이름들을 명시할 수 있다.

[root@sunguru backup]# rm -rf etc
[root@sunguru backup]#
[root@sunguru backup]# ls
etc_2016071001.tar  etc_2016071001.tar.bz2  etc_2016071001.tar.gz  lost+found
[root@sunguru backup]#
[root@sunguru backup]# mkdir etc
[root@sunguru backup]#
[root@sunguru backup]# tar -xf etc_2016071001.tar -C /backup/etc ./group ./shadow ./passwd
[root@sunguru backup]#
[root@sunguru backup]# ls -l etc
total 12
-rw-r--r--. 1 root root  895 Jul 10 19:18 group
-rw-r--r--. 1 root root 1979 Jul 10 19:18 passwd
----------. 1 root root 1156 Jul 10 19:18 shadow
[root@sunguru backup]#  

압축된 tar 파일 압축 파일 풀지 않고 파일 복구하기 위해 파이프라인(|) 기호를 사용할 수 있다.

[root@sunguru backup]# cat etc_2016071001.tar.gz | tar -xzf - -C /backup/etc 2> /dev/null
[root@sunguru backup]#
[root@sunguru backup]# ls -Rl etc | wc -l
3100
[root@sunguru backup]#
[root@sunguru backup]#
[root@sunguru backup]# ls
etc  etc_2016071001.tar  etc_2016071001.tar.bz2  etc_2016071001.tar.gz  lost+found
[root@sunguru backup]# 

▶ 테이프 디바이스를 활용한 tar 백업

아래는 mtx 명령을 이용하여 L700 테이프 라이브러리 슬롯 1번에 있는 테이프 미디어를 드라이브 0번에 삽입한 후 mt 명령을 이용하여 미디어를 제어, 이를 제일 앞으로 감은 후(rewind) /dev/st0 드라이브를 통해 테이프 미디어에 /etc 디렉터리에 있는 파일을 백업하는 것을 보여준다.

[root@centos64 mhvtl]# lsscsi -g | grep L700
[3:0:0:0]    mediumx STK      L700             0105  /dev/sch0  /dev/sg10
[root@centos64 mhvtl]#
[root@centos64 mhvtl]# mtx -f /dev/sg10 status | head -7
  Storage Changer /dev/sg10:4 Drives, 43 Slots ( 4 Import/Export )
Data Transfer Element 0:Empty
Data Transfer Element 1:Empty
Data Transfer Element 2:Empty
Data Transfer Element 3:Empty
      Storage Element 1:Full :VolumeTag=E01001L4                         
      Storage Element 2:Full :VolumeTag=E01002L4                         
[root@centos64 mhvtl]#
[root@centos64 mhvtl]# mtx -f /dev/sg10 load 1 0
Loading media from Storage Element 1 into drive 0...done
[root@centos64 mhvtl]#
[root@centos64 mhvtl]# mtx -f /dev/sg10 status | head -7
  Storage Changer /dev/sg10:4 Drives, 43 Slots ( 4 Import/Export )

Data Transfer Element 0:Full (Storage Element 1 Loaded):VolumeTag = E01001L4                     
Data Transfer Element 1:Empty
Data Transfer Element 2:Empty
Data Transfer Element 3:Empty
      Storage Element 1:Empty
      Storage Element 2:Full :VolumeTag=E01002L4                         
[root@centos64 mhvtl]#
[root@centos64 mhvtl]# mt -f /dev/st0 rewind
[root@centos64 mhvtl]# mt -f /dev/st0 status
SCSI 2 tape drive:
File number=0, block number=0, partition=0.
Tape block size 0 bytes. Density code 0x46 (LTO-4).
Soft error count since last status=0
General status bits on (41010000):
 BOT ONLINE IM_REP_EN
[root@centos64 mhvtl]#
[root@centos64 mhvtl]# cd /etc
[root@centos64 etc]#
[root@centos64 etc]# tar -cf /dev/st0 ./*
[root@centos64 etc]# mt -f /dev/st0 rewind
[root@centos64 etc]#
[root@centos64 etc]# tar -tf /dev/st0 | wc -l
2209
[root@centos64 etc]# 




■ mt 명령

mt 명령은 테이프 드라이브 안에 있는 미디어를 제어하기 위해 사용되는 명령이다.


1). 명령 형식

mt [ -f DEVICE_NAME ] OPERATION [ COUNT ]

2). Operation

Operation
내 용
rewind
 테이프를 처음으로 되돌린다.
offline
 테이프를 드라이브에서 배출한다.
status
 테이프 드라이브의 상태 정보를 출력한다.
eod
 데이터의 끝으로 이동한다.
erase
 테이프에 있는 데이터를 삭제하여 초기화한다.
fsf COUNT
 현재 구간에서 앞(Forward)으로 구간 이동을 COUNT 수 만큼 하기 위해 사용한다.
bsfm COUNT
 현재 구간에서 뒤(Backward)로 구간 이동을 COUNT 수 만큼 하기 위해 사용한다.

3). 예제

현재 테이프 미디어에는 /etc 디렉터리에 있는 파일들을 tar 백업한 Sub Volume이 하나가 있다. 테이프를 하나의 볼륨(Volume)으로 본다면 이 일부분에 /etc/에 대한 백업 데이터가 있을 것이다. 이를 백업 이미지라 부르고 그 구간을  서브 볼륨(Sub Volume)이라고 하기도 한다.

아래는 /dev/st0에 있는 미디어를 맨 앞으로 되돌리고 그 후 데이터의 끝으로 이동하였다. 그러면 /etc 디렉터리를 백업한 다음 구간에 가서 테이프가 정지한다. 왜냐하면 rewind를 뜻하는 n 문자를 st0 앞에 적었기 때문이다. 그리고 /root에 있는 파일들을 tar 명령을 사용하여 /dev/nst0 디바이스를 통해 테이프 미디어에 백업하였다. 그리고 다시 /usr/sbin 디렉터리에 있는 파일들을 백업하였다.

[root@centos64 etc]# mt -f /dev/st0 rewind
[root@centos64 etc]# mt -f /dev/nst0 eod
[root@centos64 etc]#
[root@centos64 etc]# cd /root
[root@centos64 ~]#
[root@centos64 ~]# tar -cf /dev/nst0 ./*
[root@centos64 home]#
[root@centos64 home]# cd /usr/sbin
[root@centos64 sbin]#
[root@centos64 sbin]# tar -cf /dev/nst0 ./*
[root@centos64 sbin]# 

그러면 미디어에 세 개의 서브 볼륨(Sub Volume)이 존재하게 된다. 첫 번째는 /etc, 두 번째는 /root, 세 번째는 /usr/sbin  디렉터리에 존재하는 파일들이 백업된 것이다. 그러면 /root 디렉터리에 있었던 파일들이 실수로 인해 유실되었다고 가정한다면 어떻게 백업본을 통해 데이터를 복원할 수 있을까?

이를 위해 /root 디렉터리로 이동 rm 명령을 사용하여 모든 파일을 삭제한다. 그런 후 미디어의 두 번째 서브 볼륨에 있는 백업 이미지로부터 데이터를 복원하기 위해 mt 명령을 이용하여 구간 이동을 한다. 그리고 tar 명령을 사용하여 데이터를 복원한 후 ls 명령을 사용하여 데이터가 정상적으로 복구되었는지 확인한다.

[root@centos64 sbin]# cd /root
[root@centos64 ~]# ls
anaconda-ks.cfg  install.log                             Music      Videos
Desktop          install.log.syslog                      Pictures
Documents        kmod-mhvtl-1.3-1.el6.elrepo.x86_64.rpm  Public
Downloads        mhvtl-utils-1.5-4.x86_64.rpm            Templates
[root@centos64 ~]#
[root@centos64 ~]# rm -rf ./*
[root@centos64 ~]#
[root@centos64 ~]# ls
[root@centos64 ~]#
[root@centos64 ~]# mt -f /dev/st0 rewind
[root@centos64 ~]# mt -f /dev/nst0 fsf 1
[root@centos64 ~]#
[root@centos64 ~]# tar -xf /dev/nst0
[root@centos64 ~]#
[root@centos64 ~]# ls
anaconda-ks.cfg  install.log                             Music      Videos
Desktop          install.log.syslog                      Pictures
Documents        kmod-mhvtl-1.3-1.el6.elrepo.x86_64.rpm  Public
Downloads        mhvtl-utils-1.5-4.x86_64.rpm            Templates
[root@centos64 ~]# 

여기까지 tar와 mt 명령에 대해 알아보았습니다. 현업에서는 내장 또는 외장형 디바이스를  사용하는 경우도 많으니 mt 명령은 반드시 알아두는 것이 좋습니다.

다음 게시물에서는 파일 압축에 대해 알아보도록 하겠습니다.






CentOS 6.6 리눅스 관리] 11.2 아카이브, 압축 및 백업/복구 - mhVTL 활용


안녕하세요. 썬구루입니다. 이전 게시물에서 CentOS 7.3에 mhVTL을 설치하는 방법에 대해 알아보았습니다. 이를 여기에서 사용하는 이유는 보통 리눅스나 유닉스 책에서 백업을 할 때 파일시스템 기반 파일로 백업하는 예가 많습니다. 하지만 실무에서 백업은 아래와 같은 방법으로 행해지고 있습니다.

  ▶ 파일시스템 기반에 파일로 백업
  ▶ 단일 테이프 디바이스를 활용한 테이프 미디어 백업 (특히 DAT 또는 LTO 드라이브)
  ▶ 테이프 라이브러리(PTL)와 백업 솔루션을 활용한 테이프 미디어 백업
  ▶ 가상 테이프 라이브러리(VTL)와 백업 솔루션을 활용한 가상 테이프 미디어 백업


저가 유닉스 엔지니어를 할 때에는 테이프 드라이브와 매체를 제어하는 명령을 테스트하기 위해 수십만 원을 주고 단일 테이프 디바이스와 DDS2 미디어를 산 적이 있습니다. 지금은 너무 오래되어 고장 나서 버렸지만 말이죠. 요즘은 그런 물리적 디바이스가 없어도 할 수 있는 방법이 있습니다. 드라이브와 미디어를 제어하는 방법을 알기 위해 그리고 이를 활용한 백업/복구 방법을 알기 위해 mhVTL을 사용하는 것입니다.

저가 공부할 때 이런 프로그램에 나왔어야 하는 것인데.. 좀 아쉬움이 남긴 하네요. 자.. 그럼 관련 디바이스 확인하는 방법과 제어하는 방법에 대해 알아보도록 하겠습니다.


■ 체인저(Changer)와 테이프 드라이브(Tape Drive) 확인

아래와 같이 lsscsi 명령을 사용하면 SCSI 디바이스의 모델과 디바이스 파일 등에 대한 정보를 확인할 수 있다.

[root@centos64 ~]# lsscsi -g
[0:0:0:0]    disk    VMware,  VMware Virtual S 1.0   /dev/sda   /dev/sg0
[2:0:0:0]    cd/dvd  NECVMWar VMware IDE CDR10 1.00  /dev/sr0   /dev/sg1
[3:0:0:0]    mediumx STK      L700             0105  /dev/sch0  /dev/sg10
[3:0:1:0]    tape    IBM      ULT3580-TD5      0105  /dev/st0   /dev/sg2
[3:0:2:0]    tape    IBM      ULT3580-TD5      0105  /dev/st1   /dev/sg3
[3:0:3:0]    tape    IBM      ULT3580-TD4      0105  /dev/st2   /dev/sg4
[3:0:4:0]    tape    IBM      ULT3580-TD4      0105  /dev/st3   /dev/sg5
[3:0:8:0]    mediumx STK      L80              0105  /dev/sch1  /dev/sg11
[3:0:9:0]    tape    STK      T10000B          0105  /dev/st4   /dev/sg6
[3:0:10:0]   tape    STK      T10000B          0105  /dev/st5   /dev/sg7
[3:0:11:0]   tape    STK      T10000B          0105  /dev/st6   /dev/sg8
[3:0:12:0]   tape    STK      T10000B          0105  /dev/st7   /dev/sg9
You have mail in /var/spool/mail/root
[root@centos64 ~]# 

위 결과 내용을 보면 STK(StorageTek) L700과 L80 테이프 라이브러리가 있는 것을 확인할 수 있다. L80은 80 개까지 테이프 미디어를 보관 운영할 수 있는 백업 라이브러리이다. L700은 대략 최대 700개(실제 678개)까지 테이프를 장착할 수 있다. 아래 그림과 같은 것을 아마 과학 영화에서 한 번쯤 보신 분들도 있을 것이다.

로봇 암(Robot Arm)이 지나다니면서 슬롯(Slot)에 삽입되어 있는 미디어를 빼내어 드라이브에 삽입하는.. 그런 장면... 테이프 라이브러리는 미디어를 이동시킬 수 있는 하나 이상의 체인저(Changer)와 테이프 드라이브가 보통 2개 이상 장착시킬 수 있다.


lsscsi -g 명령에서 아래 내용은 L700과 L80 테이프 라이브러리의 체인저를 나타낸다.

[3:0:0:0]    mediumx STK      L700             0105  /dev/sch0  /dev/sg18
[3:0:8:0]    mediumx STK      L80              0105  /dev/sch1  /dev/sg19

lsscsi -g 명령에서 아래 내용은 L700에 장착된 테이프 드라이브를 나타낸다. 초록색으로 표시된 키워드로 인터넷 검색을 하면 관련된 사진을 확인할 수 있다.

[3:0:1:0]    tape    IBM      ULT3580-TD5      0105  /dev/st0   /dev/sg10
[3:0:2:0]    tape    IBM      ULT3580-TD5      0105  /dev/st1   /dev/sg11
[3:0:3:0]    tape    IBM      ULT3580-TD4      0105  /dev/st2   /dev/sg12
[3:0:4:0]    tape    IBM      ULT3580-TD4      0105  /dev/st3   /dev/sg13

아래 명령을 사용하면 디바이스에 대한 좀 더 상세한 정보를 확인할 수 있다.

[root@centos64 ~]# lsscsi -c -t [3:0:0:0]
Attached devices:
Host: scsi3 Channel: 00 Target: 00 Lun: 00
  Vendor: STK      Model: L700             Rev: 0105
  Type:   Medium Changer                   ANSI SCSI revision: 05
[root@centos64 ~]#
[root@centos64 ~]# lsscsi -c -t [3:0:1:0]
Attached devices:
Host: scsi3 Channel: 00 Target: 01 Lun: 00
  Vendor: IBM      Model: ULT3580-TD5      Rev: 0105
  Type:   Sequential-Access                ANSI SCSI revision: 05
[root@centos64 ~]# 




■ mtx 명령

mtx 명령은 SCSI 미디어 체인저(Changer)를 제어하기 위해 사용되는 명령이다. 다시 말해 체인저를 제어하여 슬롯에 있는 백업 테이프를 드라이브에 넣거나 뺄 수 있다.

1). 명령형식

mtx [ -f SCSI Generic Device ] COMMAND [ command ... ]

2). COMMAND

체인저(Changer)에 내려질 명령을 나타낸다.

Sl_num : Slot number
Drv_num : Drive number

Command
내 용
status
 체인저, 드라이브, 슬롯에 대한 상태 정보를 보여준다.
load Sl_num Drv_num
 특정 슬롯에 있는 테이프를 특정 드라이브로 옮기기 위해 사용한다.
unload Sl_num Drv_num
 특정 드라이브에 있는 테이프 빼내어 특정 슬롯으로 옮기기 위해 사용한다.
inquiry
 디바이스에 대한 정보를 확인하기 위해 사용한다. ( Product Type, Vendor ID, Product ID 등)
inventory
 체인저가 이동하면서 슬롯에 있는 테이프 변동사항이 있는지 확인하고 정보 업데이트를 하기 위해  사용.
position Sl_num
 체인터를 특정 슬롯에 위치시키기 위해 사용한다. 

3). 예제

아래는 L700에 있는 체인저, 드라이브, 슬롯에 있는 테이프 미디어 정보를 확인하기 위해 실행한 명령이다. 미디어 측면에는 이를 구분하기 위한 바코드가 붙어 있는데 E01001L4는 바코드 번호이다.

[root@centos64 ~]# mtx -f /dev/sg10 status

  Storage Changer /dev/sg18:4 Drives, 43 Slots ( 4 Import/Export )
Data Transfer Element 0:Empty
Data Transfer Element 1:Empty
Data Transfer Element 2:Empty
Data Transfer Element 3:Empty
      Storage Element 1:Full :VolumeTag=E01001L4                     
      Storage Element 2:Full :VolumeTag=E01002L4                     
      Storage Element 3:Full :VolumeTag=E01003L4                     
      Storage Element 4:Full :VolumeTag=E01004L4                     
      Storage Element 5:Full :VolumeTag=E01005L4                     
      Storage Element 6:Full :VolumeTag=E01006L4                     
      Storage Element 7:Full :VolumeTag=E01007L4                     
      Storage Element 8:Full :VolumeTag=E01008L4                     
      Storage Element 9:Full :VolumeTag=E01009L4                     
      Storage Element 10:Full :VolumeTag=E01010L4                     
      Storage Element 11:Full :VolumeTag=E01011L4                     
      Storage Element 12:Full :VolumeTag=E01012L4                     
      Storage Element 13:Full :VolumeTag=E01013L4                     
      Storage Element 14:Full :VolumeTag=E01014L4                     
      Storage Element 15:Full :VolumeTag=E01015L4                     
      Storage Element 16:Full :VolumeTag=E01016L4                     
      Storage Element 17:Full :VolumeTag=E01017L4                     
      Storage Element 18:Full :VolumeTag=E01018L4                     
      Storage Element 19:Full :VolumeTag=E01019L4                     
      Storage Element 20:Full :VolumeTag=E01020L4                     
      Storage Element 21:Empty
      Storage Element 22:Full :VolumeTag=CLN101L4                     
      Storage Element 23:Full :VolumeTag=CLN102L5                     
      Storage Element 24:Empty
      Storage Element 25:Empty
      Storage Element 26:Empty
      Storage Element 27:Empty
      Storage Element 28:Empty
      Storage Element 29:Empty
      Storage Element 30:Full :VolumeTag=F01030L5                     
      Storage Element 31:Full :VolumeTag=F01031L5                     
      Storage Element 32:Full :VolumeTag=F01032L5                     
      Storage Element 33:Full :VolumeTag=F01033L5                     
      Storage Element 34:Full :VolumeTag=F01034L5                     
      Storage Element 35:Full :VolumeTag=F01035L5                     
      Storage Element 36:Full :VolumeTag=F01036L5                     
      Storage Element 37:Full :VolumeTag=F01037L5                     
      Storage Element 38:Full :VolumeTag=F01038L5                     
      Storage Element 39:Full :VolumeTag=F01039L5                     
      Storage Element 40 IMPORT/EXPORT:Empty
      Storage Element 41 IMPORT/EXPORT:Empty
      Storage Element 42 IMPORT/EXPORT:Empty
      Storage Element 43 IMPORT/EXPORT:Empty

[root@centos64 ~]#

아래는 각 디바이스에 대한 정보를 확인하기 위해 사용한 명령이다.

[root@centos64 ~]# mtx -f /dev/sg10 inquiry
Product Type: Medium Changer
Vendor ID: 'STK     '
Product ID: 'L700            '
Revision: '0105'
Attached Changer API: No
[root@centos64 ~]#
[root@centos64 ~]# mtx -f /dev/sg0 inquiry
Product Type: Disk Drive
Vendor ID: 'VMware, '
Product ID: 'VMware Virtual S'
Revision: '1.0 '
Attached Changer API: No
[root@centos64 ~]# 

아래는 슬롯 1번에 있는 테이프 미디어를 드라이브 0번으로 이동시키는 명령이다.

[root@centos64 ~]# mtx -f /dev/sg10 status | grep -E "Data|VolumeTag"| head
Data Transfer Element 0:Empty
Data Transfer Element 1:Empty
Data Transfer Element 2:Empty
Data Transfer Element 3:Empty
      Storage Element 1:Full :VolumeTag=E01001L4                         
      Storage Element 2:Full :VolumeTag=E01002L4                         
      Storage Element 3:Full :VolumeTag=E01003L4                         
      Storage Element 4:Full :VolumeTag=E01004L4                         
      Storage Element 5:Full :VolumeTag=E01005L4                         
      Storage Element 6:Full :VolumeTag=E01006L4                         
[root@centos64 ~]#
[root@centos64 ~]# mtx -f /dev/sg10 load 1 0
Loading media from Storage Element 1 into drive 0...done
[root@centos64 ~]#
[root@centos64 ~]# mtx -f /dev/sg10 status | grep -E "Data|VolumeTag"| head
Data Transfer Element 0:Full (Storage Element 1 Loaded):VolumeTag = E01001L4                         Data Transfer Element 1:Empty
Data Transfer Element 2:Empty
Data Transfer Element 3:Empty
      Storage Element 2:Full :VolumeTag=E01002L4                         
      Storage Element 3:Full :VolumeTag=E01003L4                         
      Storage Element 4:Full :VolumeTag=E01004L4                         
      Storage Element 5:Full :VolumeTag=E01005L4                         
      Storage Element 6:Full :VolumeTag=E01006L4                         
      Storage Element 7:Full :VolumeTag=E01007L4                         
[root@centos64 ~]# 

아래는 드라이브 0번에 있는 테이프 미디어를 슬롯 0으로 이동시키는 명령이다.

[root@centos64 ~]# mtx -f /dev/sg10 unload 1 0
Unloading drive 0 into Storage Element 1...done
[root@centos64 ~]#
[root@centos64 ~]# mtx -f /dev/sg10 status | grep -E "Data|VolumeTag"| head
Data Transfer Element 0:Empty
Data Transfer Element 1:Empty
Data Transfer Element 2:Empty
Data Transfer Element 3:Empty
      Storage Element 1:Full :VolumeTag=E01001L4                         
      Storage Element 2:Full :VolumeTag=E01002L4                         
      Storage Element 3:Full :VolumeTag=E01003L4                         
      Storage Element 4:Full :VolumeTag=E01004L4                         
      Storage Element 5:Full :VolumeTag=E01005L4                         
      Storage Element 6:Full :VolumeTag=E01006L4                         
[root@centos64 ~]# 




■ mhVTL 시작/종료

mhVTL에 관련된 프로세스들은 쉘 스크립트 파일을 통해 시작 또는 종료시킬 수 있다. 아래는 mhVTL 관련 모듈과 프로세스들을 확인하는 명령이다.

[root@centos64 ~]# lsmod | grep -i vtl
mhvtl                  21952  30
[root@centos64 ~]#
[root@centos64 ~]# ps -ef | grep -i vtl
vtl       2714     1  0 02:47 ?        00:00:00 vtltape -q 11 -v
vtl       2717     1  0 02:47 ?        00:00:00 vtltape -q 12 -v
vtl       2721     1  0 02:47 ?        00:00:00 vtltape -q 13 -v
vtl       2724     1  0 02:47 ?        00:00:00 vtltape -q 14 -v
vtl       2727     1  0 02:47 ?        00:00:00 vtltape -q 31 -v
vtl       2730     1  0 02:47 ?        00:00:00 vtltape -q 32 -v
vtl       2741     1  0 02:47 ?        00:00:00 vtltape -q 33 -v
vtl       2746     1  0 02:47 ?        00:00:00 vtltape -q 34 -v
vtl       2752     1  0 02:47 ?        00:00:00 vtllibrary -q 10 -v
vtl       2755     1  0 02:47 ?        00:00:00 vtllibrary -q 30 -v
root     29335 28966  0 05:01 pts/1    00:00:00 grep -i vtl
[root@centos64 ~]# 

1). mhVTL 종료

아래와 같은 명령을 사용하면 mhVTL 관련된 프로세스를 내릴 수 있다. ( /etc/init.d/mhvtl stop )

[root@centos64 ~]# /etc/init.d/mhvtl stop
shutdown of mhvtl
   Sending exit to 11
   Sending exit to 12
   Sending exit to 13
   Sending exit to 14
   Sending exit to 31
   Sending exit to 32
   Sending exit to 33
   Sending exit to 34
   Sending exit to 10
   Sending exit to 30
[root@centos64 ~]#
[root@centos64 ~]# ps -ef | grep -i vtl
root     29393 28966  0 05:03 pts/1    00:00:00 grep -i vtl
[root@centos64 ~]#

2). mhVTL 시작

아래와 같은 명령을 실행하면 mhVTL 프로세스를 실행시킬 수 있다. ( /etc/init.d/mhvtl start )

[root@centos64 ~]# /etc/init.d/mhvtl start
You should think updating the kernel module for these
 daemons to 0.18.15.
Please see https://sites.google.com/site/linuxvtl2/home?pli=1#mhvtl-kernel-module
vtllibrary process PID is 29599
vtllibrary process PID is 29602
[root@centos64 ~]#
[root@centos64 ~]# ps -ef | grep -i vtl
vtl      29513     1  0 05:06 ?        00:00:00 vtltape -q 11 -v
vtl      29516     1  0 05:06 ?        00:00:00 vtltape -q 12 -v
vtl      29522     1  0 05:06 ?        00:00:00 vtltape -q 13 -v
vtl      29563     1  0 05:06 ?        00:00:00 vtltape -q 14 -v
vtl      29570     1  0 05:06 ?        00:00:00 vtltape -q 31 -v
vtl      29577     1  0 05:06 ?        00:00:00 vtltape -q 32 -v
vtl      29584     1  0 05:06 ?        00:00:00 vtltape -q 33 -v
vtl      29591     1  0 05:06 ?        00:00:00 vtltape -q 34 -v
vtl      29599     1  0 05:06 ?        00:00:00 vtllibrary -q 10 -v
vtl      29602     1  0 05:06 ?        00:00:00 vtllibrary -q 30 -v
root     29607 28966  0 05:06 pts/1    00:00:00 grep -i vtl
[root@centos64 ~]# 

■ mhVTL 구성 파일 및 디렉터리

1). /opt/mhvtl

이 디렉터리는 파일로 된 가상 테이프 미디어가 존재하는 디렉터리이다. 각 이름은 테이프에 대한 바코드 번호를 나타낸다. 이 디렉터리의 특정 파일에 백업한 데이터가 누적되도록 되어 있다.

[root@centos64 mhvtl]# cd /opt/mhvtl
[root@centos64 mhvtl]# ls
CLN101L4  E01007L4  E01016L4  F01034L5  G03004TA  G03013TA  G03022TA  G03031TA
CLN102L5  E01008L4  E01017L4  F01035L5  G03005TA  G03014TA  G03023TA  G03032TA
CLN303TA  E01009L4  E01018L4  F01036L5  G03006TA  G03015TA  G03024TA  G03033TA
E01001L4  E01010L4  E01019L4  F01037L5  G03007TA  G03016TA  G03025TA  G03034TA
E01002L4  E01011L4  E01020L4  F01038L5  G03008TA  G03017TA  G03026TA  G03035TA
E01003L4  E01012L4  F01030L5  F01039L5  G03009TA  G03018TA  G03027TA  G03036TA
E01004L4  E01013L4  F01031L5  G03001TA  G03010TA  G03019TA  G03028TA  G03037TA
E01005L4  E01014L4  F01032L5  G03002TA  G03011TA  G03020TA  G03029TA  G03038TA
E01006L4  E01015L4  F01033L5  G03003TA  G03012TA  G03021TA  G03030TA  G03039TA
[root@centos64 mhvtl]# 

2). /etc/mhvtl/device.conf

mhvtl에 의해 사용되는 테이프 라이브러리, 드라이브에 관련된 디바이스 정보를 가지고 있는 파일이다. 사용하지 않을 디바이스들은 # 기호로 주석 처리를 하면 된다.

# Each 'record' starts at column 1
# Serial num max len is 10.
# Compression: factor X enabled 0|1
#     Where X is zlib compression factor 1 = Fastest compression
#      9 = Best compression
#     enabled 0 == off, 1 == on
#
# fifo: /var/tmp/mhvtl
# If enabled, data must be read from fifo, otherwise daemon will block
# trying to write.
# e.g. cat /var/tmp/mhvtl (in another terminal)
Library: 10 CHANNEL: 00 TARGET: 00 LUN: 00
 Vendor identification: STK
 Product identification: L700
 Unit serial number: XYZZY_A
 NAA: 10:22:33:44:ab:00:00:00
 Home directory: /opt/mhvtl
 PERSIST: False
 Backoff: 400
# fifo: /var/tmp/mhvtl

3). /etc/mhvtl/mhvtl.conf

mhvtl에 의해 사용되는 테이프 미디어에 관련된 용량 최대 크기와 구성 파일이 존재하는 디렉터리 정보를 가지고 있는 파일이다. 보통 용량(CAPACITY)에 대한 설정만 변경한다.

[root@centos64 mhvtl]# more /etc/mhvtl/mhvtl.conf

# Home directory for config file(s)
MHVTL_CONFIG_PATH=/etc/mhvtl

# Default media capacity (500 M)
CAPACITY=500

# Set default verbosity [0|1|2|3]
VERBOSE=1

# Set kernel module debuging [0|1]
VTL_DEBUG=0
[root@centos64 mhvtl]# 

여기까지 mhvtml에 대한 구성 파일과 서비스를 올리고 내리는 방법 그리고 테이프 미디어를 이동시키는 방법에 대해 알아보았습니다. 다음 게시물에서는 tar 와 mt 명령에 대해 알아보도록 하겠습니다.