Linux server backup SOP (using mdadm)
2013/2/8 更新 by Henry
1. 關機
shutdown
2. 拔出HDD0.
unplug HDD0.
3. 用HDD1單獨開機,確認無誤。
power on by HDD1, confirm OS was booted up.
4. 關機,拔出HDD1,插入HDD0,確保HDD0開機無誤。
power off, unplug HDD1, insert HDD0 and confirm HDD0 can boot up into OS.
5. HDD0開機後,接著進行對HDD2的mirror. (HDD2 先不要放進去)
After HDD0 was booted up, we can continue to mirror HDD0 to HDD2 (HDD2 will be insert into server at step 7.
6. s001a:~ # mdadm --detail /dev/md0
....
....
Number Major Minor RaidDevice State
0 8 1 0 active sync /dev/sda1
1 0 0 1 removed
0 8 1 0 active sync /dev/sda1
1 0 0 1 removed
或著是用fdisk -l來看。
接著插入HDD2
PS. 一般而言,原本的HDD會被系統認做/dev/sda ,Online插入的新硬碟,會被認作/dev/sdb , 可是,若這台Server有串接Storage,在用單一顆硬碟開機後,狀況會是/dev/sda 是HDD0, 接接著這些 /dev/sdb, /dev/sdc, /dev/sdd, /dev/sde.....都是Storage劃分給Server的硬碟,因此插入新硬碟後,新硬碟的編號會是在Storage之後,比如是/dev/sdf。
接著可直接跳到STEP 10.
8.[WARNING]若是原本就是這台主機的備份硬碟,Step8~9 以前已經做過了,不需要再做,要非常小心sda/sdb的順序,以及對應到哪顆實體硬碟,否則會導致資料全部損毀。
copy old hdd partition (sda) to new hdd (sdb) by
sfdisk -d /dev/sda | sfdisk /dev/sdb
9. [WARNING] compare partition table is the same with /dev/sda
fdisk -l /dev/sda
fdisk -l /dev/sdb
10. Add mirror HDD to RAID.
注意:mdX所對應的sdbX一定要先用mdadm --detail /dev/md0來確認,千萬不要矇著眼做,如果mirror錯partition, 系統是不會有問題,但是一定無法rebuild成功。
mdadm /dev/md0 --add /dev/sdb1
mdadm /dev/md1 --add /dev/sdb2
mdadm /dev/md2 --add /dev/sdb3
mdadm /dev/md3 --add /dev/sdb5
11. Checking rebuilding progress
mdadm --detail /dev/md0
mdadm --detail /dev/md1
mdadm --detail /dev/md2
mdadm --detail /dev/md3
12. After rebuilding successful, setup Grub Boot Loader to let each HD can boot by itself.
先確認哪一個md mount 給 / , 這邊範例是/dev/md0 mount 給 / .
12.1. s001a:~ # df -h
Filesystem Size Used Avail Use% Mounted on
/dev/md0 26G 12G 14G 47% /
udev 7.9G 204K 7.9G 1% /dev
/dev/md2 11G 46M 10G 1% /home
/dev/md3 13G 97M 12G 1% /CDRagent
Filesystem Size Used Avail Use% Mounted on
/dev/md0 26G 12G 14G 47% /
udev 7.9G 204K 7.9G 1% /dev
/dev/md2 11G 46M 10G 1% /home
/dev/md3 13G 97M 12G 1% /CDRagent
12.2 接著確認md0 是用/dev/sdb1
#mdadm --detail /dev/md0
...
...
Number Major Minor RaidDevice State
0 8 1 0 active sync /dev/sda1
1 8 17 1 active sync /dev/sdb1
0 8 1 0 active sync /dev/sda1
1 8 17 1 active sync /dev/sdb1
12.3 接著確認/dev/sdb1已經有設上Boot Flag.
s001a:~ # fdisk -l /dev/sdb
Disk /dev/sdb: 146.8 GB, 146815737856 bytes
255 heads, 63 sectors/track, 17849 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 3264 26218048+ fd Linux raid autodetect
/dev/sdb2 3265 3526 2104515 fd Linux raid autodetect
Disk /dev/sdb: 146.8 GB, 146815737856 bytes
255 heads, 63 sectors/track, 17849 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 3264 26218048+ fd Linux raid autodetect
/dev/sdb2 3265 3526 2104515 fd Linux raid autodetect
/dev/sdb3 3527 4832 10490445 fd Linux raid autodetect
/dev/sdb4 4833 17848 104551020 f W95 Ext'd (LBA)
/dev/sdb5 4833 6399 12586896 fd Linux raid autodetect
/dev/sdb4 4833 17848 104551020 f W95 Ext'd (LBA)
/dev/sdb5 4833 6399 12586896 fd Linux raid autodetect
12.4 接著進Grub設定/dev/sda 與dev/sdb的MBR都能夠正確找到開機磁區與Kernel位置。
grub
device (hd0) /dev/sda ##定義在Grub中hd0代表/dev/sda
root (hd0,0) ##hd0,0 代表/dev/sda1, hd0,1 代表/dev/sda2 ,以此類推
setup (hd0)
device (hd1) /dev/sdb ##定義在Grub中hd1代表/dev/sdb
root (hd1,0) ##hd0,0 代表/dev/sdb1, hd0,1 代表/dev/sdb2 ,以此類推
setup (hd1)
quit
13. 大功告成。
沒有留言:
張貼留言