Last active
February 14, 2020 19:21
-
-
Save bigntallmike/d8a5dd3677798e30a4ff8efec895db43 to your computer and use it in GitHub Desktop.
Rebuild raid concept
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python -ttu | |
# | |
# For a set of disks that were previously in a RAID set, build an image of the data such as it was, | |
# ignoring parity. | |
class RAIDDEV: | |
def __init__(self, DEVICE, OFFSET=0): | |
self.DATA=file(DEVICE, r) | |
self.DATA.seek(OFFSET) | |
# Set this to the byte offset of the start of data on *each* disk | |
OFFSET=0 | |
# Make a list of each source device, in RAID order | |
DEVICES=(RAIDDEV('/dev/sda', OFFSET), RAIDDEV('/dev/sdb', OFFSET), RAIDDEV('/dev/sdc', OFFSET)) | |
# This is ignored and assumed | |
RAIDLEVEL=5 | |
# Set the stripe size used in creating the original raid set | |
STRIPESIZE=(128 * 1024) | |
# Configure the output file | |
OUTFILE=file("/mnt/disk.img", "w") | |
# Assumes the first parity data is stored on the last disk on the first loop | |
XORPOS=len(DEVICES)-1 | |
while True: | |
for DEVICE in DEVICES: | |
if DEVICES.index(DEVICE) == XORPOS: | |
# Skip over the stripe containing redundancy | |
next | |
OUTFILE.write(DEVICE.DATA.read(STRIPESIZE)) | |
XORPOS+=1 | |
if (XORPOS > len(DEVICES): | |
XORPOS=0 | |
# Note: this program will exit on EOF and should instead exit on all disks being completed instead. | |
# As a result, N-1 stripes of data could be lost at the end of the disk. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment