Linux CentOS での システム丸ごと バックアップ & リストア
テスト環境 †
- マシンは 例のテスト機 ハードディスクは2台接続 sda sdb
- ネット環境はNATルーター下のLAN内
- CentOS5.2 インストール用DVDからほぼ全て標準設定のままインストール
- sdb は インストールに使用するドライブからチェックを外した。
- インストーラが標準で設定してくれるディスクパーティション設定は
sda | /dev/sda1 | /boot | 100Mb | |
| /dev/sda2 | LVM(VolGroup00) | 残り全部 | LVM | /dev/VolGroup00/LogVol00 | / | 残り全部 |
| | /dev/VolGroup00/LogVol01 | swap | 2G |
- LVMスナップショット・RAID 等については後日試す
- マルチユーザモードのままでGo!(FreeBSDで忙しく動いているサーバでも今まで問題が起きた事がないから。。)
バックアップ前のファイルシステムの構造 †
- fdisk -l
Disk /dev/sda: 250.0 GB, 250058268160 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = シリンダ数 of 16065 * 512 = 8225280 bytes
デバイス Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 30401 244091610 8e Linux LVM
dump †
- dump0 dump1 定期的にcronで動かす設定も後日。。。。
- この時に画面に表示されるもの↓↓↓↓↓↓をファイルに記録して置きたいが方法が不明、cronでdumpを実行すればメールで送ってくるはず?
DUMP: Date of this level 0 dump: Tue Mar 3 15:19:57 2009
DUMP: Dumping /dev/mapper/VolGroup00-LogVol00 (/) to root.dump0
DUMP: Label: none
DUMP: Writing 10 Kilobyte records
DUMP: mapping (Pass I) [regular files]
DUMP: mapping (Pass II) [directories]
DUMP: estimated 2650150 blocks.
DUMP: Volume 1 started with block 1 at: Tue Mar 3 15:21:49 2009
DUMP: dumping (Pass III) [directories]
DUMP: dumping (Pass IV) [regular files]
DUMP: 70.43% done at 6221 kB/s, finished in 0:02
DUMP: Closing root.dump0
DUMP: Volume 1 completed at: Tue Mar 3 15:29:37 2009
DUMP: Volume 1 3007150 blocks (2936.67MB)
DUMP: Volume 1 took 0:07:48
DUMP: Volume 1 transfer rate: 6425 kB/s
DUMP: 3007150 blocks (2936.67MB) on 1 volume(s)
DUMP: finished in 468 seconds, throughput 6425 kBytes/sec
DUMP: Date of this level 0 dump: Tue Mar 3 15:19:57 2009
DUMP: Date this dump completed: Tue Mar 3 15:29:37 2009
DUMP: Average transfer rate: 6425 kB/s
DUMP: DUMP IS DONE
DUMP: Date of this level 0 dump: Tue Mar 3 15:19:46 2009
DUMP: Dumping /dev/sda1 (/boot) to boot.dump0
DUMP: Label: /boot
DUMP: Writing 10 Kilobyte records
DUMP: mapping (Pass I) [regular files]
DUMP: mapping (Pass II) [directories]
DUMP: estimated 12066 blocks.
DUMP: Volume 1 started with block 1 at: Tue Mar 3 15:19:46 2009
DUMP: dumping (Pass III) [directories]
DUMP: dumping (Pass IV) [regular files]
DUMP: Closing boot.dump0
DUMP: Volume 1 completed at: Tue Mar 3 15:19:48 2009
DUMP: Volume 1 12130 blocks (11.85MB)
DUMP: Volume 1 took 0:00:02
DUMP: Volume 1 transfer rate: 6065 kB/s
DUMP: 12130 blocks (11.85MB) on 1 volume(s)
DUMP: finished in 2 seconds, throughput 6065 kBytes/sec
DUMP: Date of this level 0 dump: Tue Mar 3 15:19:46 2009
DUMP: Date this dump completed: Tue Mar 3 15:19:48 2009
DUMP: Average transfer rate: 6065 kB/s
DUMP: DUMP IS DONE
restore †
- 壊れたディスクを交換してインストールDVDから起動する
#起動時
boot:linux resuce
- レスキューモードで起動する、ネットワークの設定はNFSを使う場合以外は不要、sysimage へのマウントも不要 を選択
- 新しいディスクにバックアップ時の構造と同じ様にを設定する
- パーテーション
#/boot用
fdisk /dev/sda
n (作成)
p (基本パーテーション)
1 (領域番号1-4の1番目)
1 (最初 シリンダ)
7 (終点 シリンダ /boot用に100Mbも多すぎるから半分位に変更してみた)
a (ブート可能フラグ)
1 (領域番号)
#LVM用
n (作成)
p (基本パーテーション)
2 (領域番号1-4の2番目)
(最初 シリンダ "default"のまま)
(終点 シリンダ "default"のままで残り全部)
t (LVM用にシステムIDを変更)
2 (領域番号1-4の2番目)
8e (Linux LVM)
#テーブルをディスクに書き込み終了する
w
- LVM
- PV
#PVリスト
lvm pvs
lvm pvscan
#PV作成
lvm pvceate /dev/sda2
- VG
#VGリスト
lvm vgs
lvm vgscan
#VGアクティブ化
lvm vgchange -ay
#VG作成
lvm vgceate -s 32m VolGroup00 /dev/sda2 (-s=PEサイズ)
- LV
#LVリスト
lvm lvs
lvm lvscan
#LV作成
lvm lvcreate -L 20G -n LogVol00 /dev/VolGroup00 ("/"用、後のスナップショット用の領域を残すために小さくした)
lvm lvcreate -L 2G -n LogVol01 /dev/VolGroup00 ("swap"用)
- ファイルシステム
#/boot
mke2fs -j -L /boot /dev/sda1 (-j=ext3対応 -L=ラベル設定)
#/
mke2fs -j /dev/VolGroup00/LogVol00
- スワップ
mkswap /dev/VolGroup00/LogVol01
- restor先をマウント時に、" -o nouser_xattr " のオプションを設定したほうが良いらしいが、エラーにならなかったので、問題が起きるまでこのまま。
- 同じく " -T /back " 等と tmp用の大容量フォルダを用意したほうが良いらしいが、エラーにならなかった(マシンのメモリ量に依存するのかな?)
ブートローダのインストール †
chroot /rest
MAKEDEV sda
grub
grub> root (hd0,0)
grub> setup (hd0)
grub> quit
終了 †
sync
exit