HDD増設!バックアップの設定もするぞ!
HDD増設
この前買ったHDDを早速サーバーに増設しましょう。
・・・というわけです。
HDD増設というわけで、物理的にケースの中に突っ込んで、ケーブルを繋げないと始まりません。
まずはサイドパネルを開けましょう。
HDDを取り出して・・・
ぶち込んで終了。
確認
きちんと認識できているか確認しておきましょう。
とりあえずサーバーにsshで接続してroot権限でfdisk -lとタイプしてEnterです。
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18  | 
						# fdisk -l Disk /dev/sdb: 3000.6 GB, 3000592982016 bytes, 5860533168 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト Disk /dev/sda: 2000.4 GB, 2000398934016 bytes, 3907029168 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O サイズ (最小 / 推奨): 4096 バイト / 4096 バイト Disk label type: dos ディスク識別子: 0x000d35dd デバイス ブート      始点        終点     ブロック   Id  システム /dev/sda1            2048     8194047     4096000   82  Linux swap / Solaris /dev/sda2   *     8194048  3907020799  1949413376   83  Linux  | 
					
/dev/sdbとして認識されていることが分かります。
念の為、S.M.A.R.T.情報で明らかな初期不良が発生してないかも確認しておきましょう。
smartctl -a /dev/sdbで情報が見れます。
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99  | 
						# smartctl -a /dev/sdb smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.10.0-229.1.2.el7.x86_64] (local build) Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org === START OF INFORMATION SECTION === Device Model:     TOSHIBA MG03ACA300 Serial Number:     LU WWN Device Id: 5 000039 4fba013b0 Firmware Version: FL1A User Capacity:    3,000,592,982,016 bytes [3.00 TB] Sector Size:      512 bytes logical/physical Rotation Rate:    7200 rpm Device is:        Not in smartctl database [for details use: -P showall] ATA Version is:   ATA8-ACS (minor revision not indicated) SATA Version is:  SATA 3.0, 6.0 Gb/s (current: 3.0 Gb/s) Local Time is:    Wed May  6 19:55:58 2015 JST SMART support is: Available - device has SMART capability. SMART support is: Enabled === START OF READ SMART DATA SECTION === SMART overall-health self-assessment test result: PASSED General SMART Values: Offline data collection status:  (0x80) Offline data collection activity                                         was never started.                                         Auto Offline Data Collection: Enabled. Self-test execution status:      (   0) The previous self-test routine completed                                         without error or no self-test has ever                                          been run. Total time to complete Offline  data collection:                (  120) seconds. Offline data collection capabilities:                    (0x5b) SMART execute Offline immediate.                                         Auto Offline data collection on/off support.                                         Suspend Offline collection upon new                                         command.                                         Offline surface scan supported.                                         Self-test supported.                                         No Conveyance Self-test supported.                                         Selective Self-test supported. SMART capabilities:            (0x0003) Saves SMART data before entering                                         power-saving mode.                                         Supports SMART auto save timer. Error logging capability:        (0x01) Error logging supported.                                         General Purpose Logging supported. Short self-test routine  recommended polling time:        (   2) minutes. Extended self-test routine recommended polling time:        ( 540) minutes. SCT capabilities:              (0x003d) SCT Status supported.                                         SCT Error Recovery Control supported.                                         SCT Feature Control supported.                                         SCT Data Table supported. SMART Attributes Data Structure revision number: 16 Vendor Specific SMART Attributes with Thresholds: ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE   1 Raw_Read_Error_Rate     0x000b   100   100   050    Pre-fail  Always       -       0   2 Throughput_Performance  0x0005   100   100   050    Pre-fail  Offline      -       0   3 Spin_Up_Time            0x0027   100   100   001    Pre-fail  Always       -       11463   4 Start_Stop_Count        0x0032   100   100   000    Old_age   Always       -       2   5 Reallocated_Sector_Ct   0x0033   100   100   050    Pre-fail  Always       -       0   7 Seek_Error_Rate         0x000b   100   100   050    Pre-fail  Always       -       0   8 Seek_Time_Performance   0x0005   100   100   050    Pre-fail  Offline      -       0   9 Power_On_Hours          0x0032   100   100   000    Old_age   Always       -       0  10 Spin_Retry_Count        0x0033   100   100   030    Pre-fail  Always       -       0  12 Power_Cycle_Count       0x0032   100   100   000    Old_age   Always       -       2 191 G-Sense_Error_Rate      0x0032   100   100   000    Old_age   Always       -       0 192 Power-Off_Retract_Count 0x0032   100   100   000    Old_age   Always       -       0 193 Load_Cycle_Count        0x0032   100   100   000    Old_age   Always       -       3 194 Temperature_Celsius     0x0022   100   100   000    Old_age   Always       -       35 (Min/Max 23/35) 196 Reallocated_Event_Count 0x0032   100   100   000    Old_age   Always       -       0 197 Current_Pending_Sector  0x0032   100   100   000    Old_age   Always       -       0 198 Offline_Uncorrectable   0x0030   100   100   000    Old_age   Offline      -       0 199 UDMA_CRC_Error_Count    0x0032   200   253   000    Old_age   Always       -       0 220 Disk_Shift              0x0002   100   100   000    Old_age   Always       -       0 222 Loaded_Hours            0x0032   100   100   000    Old_age   Always       -       0 223 Load_Retry_Count        0x0032   100   100   000    Old_age   Always       -       0 224 Load_Friction           0x0022   100   100   000    Old_age   Always       -       0 226 Load-in_Time            0x0026   100   100   000    Old_age   Always       -       113 240 Head_Flying_Hours       0x0001   100   100   001    Pre-fail  Offline      -       0 SMART Error Log Version: 1 No Errors Logged SMART Self-test log structure revision number 1 No self-tests have been logged.  [To run self-tests, use: smartctl -t] SMART Selective self-test log data structure revision number 1  SPAN  MIN_LBA  MAX_LBA  CURRENT_TEST_STATUS     1        0        0  Not_testing     2        0        0  Not_testing     3        0        0  Not_testing     4        0        0  Not_testing     5        0        0  Not_testing Selective self-test flags (0x0):   After scanning selected spans, do NOT read-scan remainder of disk. If Selective self-test is pending on power-up, resume after 0 minute delay.  | 
					
次はパーティションを作ります。
3TBのHDDなのでfdiskコマンドではなくpartedコマンドを使います。
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34  | 
						# parted /dev/sdb parted /dev/sdb GNU Parted 3.1 /dev/sdb を使用 GNU Parted へようこそ! コマンド一覧を見るには 'help' と入力してください。 (parted) mktable 新しいディスクラベル? gpt                                                  警告: いま存在している /dev/sdb のディスクラベルは破壊され、このディスクの全データが失われます。続行しますか? はい(Y)/Yes/いいえ(N)/No? Y                                                (parted) mkpart backup ext4 0% 100% (parted) print all モデル: ATA TOSHIBA MG03ACA3 (scsi) ディスク /dev/sdb: 3001GB セクタサイズ (論理/物理): 512B/512B パーティションテーブル: gpt ディスクフラグ:  番号  開始    終了    サイズ  ファイルシステム  名前    フラグ  1    1049kB  3001GB  3001GB                    backup モデル: ATA TOSHIBA DT01ACA2 (scsi) ディスク /dev/sda: 2000GB セクタサイズ (論理/物理): 512B/4096B パーティションテーブル: msdos ディスクフラグ:  番号  開始    終了    サイズ  タイプ   ファイルシステム  フラグ  1    1049kB  4195MB  4194MB  primary  linux-swap(v1)  2    4195MB  2000GB  1996GB  primary  ext4              boot (parted) q                                                                 通知: 必要であれば /etc/fstab を更新するのを忘れないようにしてください。  | 
					
フォーマットはmkfsコマンドです。
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23  | 
						# mkfs -t ext4 /dev/sdb1 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 183148544 inodes, 732566272 blocks 36628313 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2881486848 22357 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, 1605632, 2654208,          4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,          102400000, 214990848, 512000000, 550731776, 644972544 Allocating group tables: done                             Writing inode tables: done                             Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done  | 
					
LinuxではWindowsみたいにHDDを繋げたらDドライブにマウントされるとかはないので、自分でマウントする場所を決める必要があります。
/etc/fstabを編集しましょう。
まずパーティションのUUIDをblkidコマンドで調べます。
| 
					 1 2  | 
						# blkid /dev/sdb1 /dev/sdb1: UUID="a3fe1f03-d6a3-45fa-a2cf-8735bcea7479" TYPE="ext4" PARTLABEL="backup" PARTUUID="cf13a7ac-0ca7-4c0d-b94d-9258647c7dcd"  | 
					
UUIDを使ってfstabを編集します。
| 
					 1  | 
						UUID=a3fe1f03-d6a3-45fa-a2cf-8735bcea7479 /backup                 ext4    defaults        0 2  | 
					
書式は
マウントするパーティション マウントポイント ファイルシステムの種類 オプション dumpの対象か否か fsckの順序
マウントするパーティション
いろんな書き方がありますが、UUIDを使うのが1番確実ですし、大抵のディストリビューションは標準でUUIDを使ったパーティションの指定をします。
マウントポイント
マウントする場所です。
存在しないパスにはマウントできないので、予めmkdirで作って置かなければいけません。
ファイルシステムの種類
ext4とかbtrfsとかntfsとかです。
オプション
オプションをここに書きますが、普通はdefaultsで事足ります。
dumpの対象か否か
1でdumpの対象になり、0でなりません。
dumpとはバックアップに使うコマンドであり、今回はバックアップするためのパーティションなので0にしています。
fsckの順序
0にするとfsckを自動的に行いません。
/ファイルシステムは1にするのが無難です。
書いたらmount -aを実行し、エラーが無いか必ず確認してください。
バックアップしよう
というわけで準備が整ったのでバックアップしていきましょう。
今回バックアップするのはNASです。
NASは結構古いHDDを使っている上に、あのSAMSUNG製HDDなのでいつ壊れてもおかしくないです。
なのでさっさとバックアップしておきましょう。
NASのマウント
/mnt/nas1にマウントしていこうと思います。
よってmkdir /mnt/nas1でディレクトリを作っておかなければいけません。
次にマウントに必要なcifs-utilsを入れましょう
| 
					 1  | 
						yum -y install cifs-utils  | 
					
終わったら実際にマウントしましょう。
NASのIPアドレスが192.168.10.100
ディレクトリが/my_dir
ユーザー名がuser1
パスワードは無しの場合は
| 
					 1  | 
						mount -t cifs -o user=user1,password= //192.168.10.100/my_dir /mnt/nas1  | 
					
となります。
きちんとマウントできたことを確認したら/etc/fstabを書きます。
| 
					 1  | 
						//192.168.10.100/my_dir /mnt/nas1 cifs user=user1,password=,defaults 1 0  | 
					
書いたらmount -aを実行し、エラーが無いか必ず確認してください。
dumpでバックアップ
dumpコマンドでバックアップしていこうと思います。
とりあえず初回は必ずフルバックアップを取ることになりますが、面倒くさいのでシングルユーザーモードに入らずにそのままやっちゃうます。
| 
					 1  | 
						dump -0u -z9 -f /backup/dump0  | 
					
これで/backup/dump0にバックアップが保存されます。
バックアップを実行するのは当然使用頻度が低い時間帯が良いのですが、当サイトは年中閑散期なのでなんの問題もないでしょう。


