Need to clone a disk of a RAID1 array to another machine remotely: Fail, Remove, clone drive, then re-add it to the array
assuming: cat /proc/mdstat
md0 : active raid1 sdb1[2] sda1[0]
488253440 blocks super 1.2 [2/2] [UU]
bitmap: 4/4 pages [16KB], 65536KB chunk
1) Fail it:
mdadm --fail /dev/md0 /dev/sdb1
set /dev/sdb1 faulty in /dev/md0
2) Remove it:
mdadm --manage /dev/md0 --re-add /dev/sdb1
mdadm: Cannot open /dev/sdb1: Device or resource busy
mdadm --remove /dev/md0 /dev/sdb1
mdadm: hot removed /dev/sdb1 from /dev/md0
3) clone it:
dd if=/dev/sdb1 bs=4096 conv=sync,noerror | pigz -c > /donnees/sdb1_image.img.gz
4) view progress of clone in new shell:
kill -USR1 <pid>
#(ps aux | grep dd finds pid)
13126009+0 enregistrements lus
13126008+0 enregistrements écrits
OR watch -n 10 kill -USR1 {pid of your DD process}
53764128768 bytes (54 GB, 50 GiB) copied, 326,995 s, 164 MB/s
5) clone mbr (master boot record)
dd if=/dev/sdb2 bs=512 of=/donnees/sdb2_mbr.img count=1
6) copy the clone files over to another server
scp -P52222 /donnees/sdb1_* user@server:/home/user
a) Howto resume broken download using rsync
rsync --partial --progress -e "ssh -p 52224" user@host:/donnees/sdb1_image.img.gz sdb1_image.img.gz
7) restore sdb1_mbr.img to another disk
dd if=/home/user/sdb1_mbr.img bs=512 of=/dev/sdb1 count=1
8) restore sdb1_image.img.gz to another disk
pigz -c /home/user/sdb1_image.img.gz | dd of=/dev/sdb1 bs=4096 conv=sync,noerror
9) Re add the device to the array
mdadm --manage /dev/md0 --re-add /dev/sdb1
mdadm: re-added /dev/sdb1
10) cat /proc/mdstat
md0 : active raid1 sdb1[2] sda1[0]
488253440 blocks super 1.2 [2/1] [U_]
[=========>...........] recovery = 47.9% (234116736/488253440) finish=17.6min speed=240358K/sec
bitmap: 4/4 pages [16KB], 65536KB chunk