Skip to content

Instantly share code, notes, and snippets.

@alevchuk
Created May 18, 2021 14:54
Show Gist options
  • Save alevchuk/cd21fbe31e37d8e588941daae326129f to your computer and use it in GitHub Desktop.
Save alevchuk/cd21fbe31e37d8e588941daae326129f to your computer and use it in GitHub Desktop.
check fs / storage for corruption
#!/bin/env python3
import os
import sys
data_dir = "checker-data"
try:
os.mkdir(data_dir)
except FileExistsError:
pass
print("Writing and reading checker data to dir: {}".format(data_dir))
count = 1
while True:
with open("checker-data/{:08}".format(count), "w") as w:
w.write(str(count) * 100)
for i in range(1, count + 1):
with open("checker-data/{:08}".format(i), "r") as r:
line = r.readlines()[0]
expected = str(i) * 100
if line != expected:
print("Found inconsistency in {}".format(i))
print("Got '{}'".format(line))
print("Expected '{}'".format(expected))
sys.exit(1)
count += 1
@alevchuk
Copy link
Author

alevchuk commented May 18, 2021

  1. in the terminal cd into a folder in the mount where you're suspecting data corruption
  2. copy and paste this python code in a file: cat > fs_checker.py
  3. chmod +x fs_checker.py
  4. run it: time ./fs_checker.py
  5. if nothing gets printed that means no issues are found
  6. ⌨️ Ctrl-c when you're tired of waiting
  7. check how much data has been written: du -sch checker-data/
  8. cleanup: rm -rf checker-data/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment