systemctl daemon-reload systemctl enable btrfs-scrub.service systemctl enable btrfs-scrub.timer systemctl start btrfs-scrub.timer
chmod 600 /root/.netrc
apt-get install curl (if you are inside a in container)
machine smtp.gmail.com | |
login [email protected] | |
password my-app-password |
#! /bin/bash | |
####################################################### | |
# This is a helper script to be used in a systemd timer | |
# or cron job to scrub all mounted btrfs filessytems | |
# | |
# $Author: gbrks | |
# $Revision 0.1 | |
# $Date: 2015.05.15 | |
# | |
# Update email address below | |
EMAIL_SUBJECT_PREFIX="$HOSTNAME BTRFS - " | |
EMAIL_ADDRESS="<email@address>" | |
LOG_FILE="/var/log/btrfs-scrub.log" | |
TMP_OUTPUT="/tmp/btrfs-scrub.$$.out" | |
# redirect all stdout to log gile | |
exec >> $LOG_FILE | |
echo "[`date -Iseconds`] btrfs scrub job started." | |
# mail header to the file | |
echo "From: "My Name" <$EMAIL_ADDRESS>" > $TMP_OUTPUT | |
echo "To: "My Name" <$EMAIL_ADDRESS>" >> $TMP_OUTPUT | |
echo "Subject: $EMAIL_SUBJECT_PREFIX Scrub Job Completed" >> $TMP_OUTPUT | |
echo "" >> "$TMP_OUTPUT" | |
# timestamp the job | |
echo "[`date -Iseconds`] btrfs scrub job started." | |
echo "btrfs scrub job started on `date -Iseconds`" >> $TMP_OUTPUT | |
echo "----------------------------------------" >> $TMP_OUTPUT | |
# for each btrfs type system mounted, scrub and record output | |
while read d m t x | |
do | |
[[ $t != "btrfs" ]] && continue | |
echo "scrubbing $m" >> $TMP_OUTPUT | |
echo "[`date -Iseconds`] scrubbing $m" | |
btrfs scrub start -Bd $m >> $TMP_OUTPUT | |
echo "" >> $TMP_OUTPUT | |
done </proc/mounts | |
echo "----------------------------------------" >> $TMP_OUTPUT | |
echo "btrfs scrub job finished on `date -Iseconds`" >> $TMP_OUTPUT | |
curl \ | |
--netrc --ssl-reqd \ | |
--mail-from "<$EMAIL_ADDRESS>" \ | |
--mail-rcpt "<$EMAIL_ADDRESS>" \ | |
--url smtps://smtp.gmail.com:465 \ | |
-T "$TMP_OUTPUT" \ | |
&& rm "$TMP_OUTPUT" || true | |
echo "[`date -Iseconds`] Scrub job ended." | |
exit 0; |
[Unit] | |
Description=btrfs scrub | |
[Service] | |
User=root | |
Type=simple | |
ExecStart=/usr/local/bin/btrfs-scrub |
[Unit] | |
Description=Runs btrfs scrub on all discs monthly | |
[Timer] | |
OnCalendar=weekly | |
[Install] | |
WantedBy=timers.target |
My improved version is here: https://github.com/ceremcem/monitor-btrfs-disk