add btrfs-scrub.py
This commit is contained in:
parent
2cef97f92b
commit
63db8162e3
2 changed files with 52 additions and 0 deletions
43
btrfs-scrub.py
Executable file
43
btrfs-scrub.py
Executable file
|
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# nonstdlib requirements: apprise
|
||||
# to be invoked via btrfs-scrub@.(timer+service)
|
||||
|
||||
import os
|
||||
import platform
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import apprise
|
||||
|
||||
MATRIX_USER = os.environ['MATRIX_USER']
|
||||
MATRIX_PASSWORD = os.environ['MATRIX_PASSWORD']
|
||||
MATRIX_ROOM = os.environ['MATRIX_ROOM']
|
||||
|
||||
MAIL_USER = os.environ['MAIL_USER']
|
||||
MAIL_PW = os.environ['MAIL_PASSWORD']
|
||||
MAIL_TO = os.environ['MAIL_TO']
|
||||
|
||||
|
||||
def report_results(res: subprocess.CompletedProcess) -> None:
|
||||
print(res.stdout)
|
||||
print(res.stderr, file=sys.stderr)
|
||||
apobj = apprise.Apprise()
|
||||
with apprise.LogCapture(level=apprise.logging.INFO) as output:
|
||||
apobj.add(f'matrixs://{MATRIX_USER}@nitro.chat/{MATRIX_ROOM}?pass={MATRIX_PASSWORD}')
|
||||
# can't specify user & pw at the start
|
||||
# https://github.com/caronc/apprise/wiki/Troubleshooting#special-characters-and-url-conflicts
|
||||
apobj.add(
|
||||
f'mailtos://@matous.dev:465?user={MAIL_USER}&stmp=mx1.matous.dev&from=Apprise Monitor <{MAIL_USER}>&pass={MAIL_PW}&to={MAIL_TO}&mode=ssl'
|
||||
)
|
||||
|
||||
title = f'{platform.node()} BTRFS scrub finished: {res.returncode}'
|
||||
apobj.notify(title=title, body=f'Summary:\n{res.stdout}\n\n{res.stderr}')
|
||||
print(output.getvalue())
|
||||
|
||||
|
||||
path = Path(sys.argv[1])
|
||||
cmd = ['/bin/btrfs', 'scrub', 'start', '-d', '-B', path]
|
||||
res = subprocess.run(cmd, text=True, capture_output=True, check=False)
|
||||
report_results(res)
|
||||
Loading…
Add table
Add a link
Reference in a new issue