以前組んだ、遠隔地にある Raspberry Pi によるソフトウェア RAID 6ストレージをオフサイトバックアップする仕組みを永らく運用していますが、この RAID がコケていることに数日経ってようやく気付き、バックアップを確認すると見事に空っぽ( RAID ボリュームのマウントに失敗した空状態を健気にコピー)。幸い機器再起動で RAID は復活しましたが、かなり肝を冷やしたのでバックアップ実行前に RAID 状態をチェックする仕組みを織り込みます。
遠隔地にあるそのRaspberry Piは週に一度、システムディスクであるSDカードのイメージをRAIDストレージへ出力しています。このタスクの吐き出したエラーメッセージで気付きました。
1 |
/bin/sh: 1: cannot create /mnt/md6/backup/homePi2.img.gz: Directory nonexistent |
実際にはこの2日前にRAID喪失が発生していたことが、毎晩実行されるオフサイトバックアップの当日のログから読み取れます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
2020-12-20_01:07:02 : Starting rsync receiving incremental file list deleting ......pdf ... ...(延々とdeleting) ... ... sent 63 bytes received 50 bytes 1.70 bytes/sec total size is 0 speedup is 0.00 2020-12-20_01:08:09 : Finished rsync Elapsed time = 67 seconds 2020-12-21_01:07:02 : Starting rsync receiving incremental file list sent 60 bytes received 47 bytes 71.33 bytes/sec total size is 0 speedup is 0.00 2020-12-21_01:07:04 : Finished rsync Elapsed time = 2 seconds |
バックアップからの復元は諦め、RAID復活の可能性を探るべく、まずはRaspberry Piのコンソールで状況を確認。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
$ uptime 09:33:45 up 4 days, 10:01, 1 user, load average: 0.07, 0.08, 0.07 $ mount /dev/mmcblk0p2 on / type ext4 (rw,noatime,data=ordered) devtmpfs on /dev type devtmpfs (rw,relatime,size=492508k,nr_inodes=123127,mode=755) sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) proc on /proc type proc (rw,relatime) tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev) devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000) tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755) tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k) tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755) cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/lib/systemd/systemd-cgroups-agent,name=systemd) cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct) cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio) cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory) cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices) cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer) cgroup on /sys/fs/cgroup/net_cls type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls) systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=22,pgrp=1,timeout=300,minproto=5,maxproto=5,direct) debugfs on /sys/kernel/debug type debugfs (rw,relatime) mqueue on /dev/mqueue type mqueue (rw,relatime) configfs on /sys/kernel/config type configfs (rw,relatime) /dev/mmcblk0p1 on /boot type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro) $ sudo mdadm --monitor --scan --test -1 This is an automatically generated mail message from mdadm A TestMessage event had been detected on md device /dev/md6. Faithfully yours, etc. P.S. The /proc/mdstat file currently contains the following: Personalities : [raid6] [raid5] [raid4] md6 : active (auto-read-only) raid6 sdb1[5] sdc1[3] sdd1[4] sda1[1] 235202560 blocks super 1.2 level 6, 512k chunk, algorithm 2 [4/4] [UUUU] bitmap: 0/1 pages [0KB], 65536KB chunk unused devices: <none> |
このRaspberry Piは24時間稼働ですが、毎週末再起動するようスケジューリングされており、uptimeはそこからの稼働時間値を示しています。この再起動後ほどなくその夜のオフサイトバックアップでストレージ空っぽ状態が記録されていることから、当日のSyslogをトレースしてみます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
Dec 19 23:32:01 homepi2 rsyslogd: [origin software="rsyslogd" swVersion="8.4.2" x-pid="511" x-info="http://www.rsyslog.com"] exiting on signal 15. Dec 19 23:32:10 homepi2 systemd[1]: Starting Create Static Device Nodes in /dev... Dec 19 23:32:10 homepi2 systemd[1]: Mounted Debug File System. Dec 19 23:32:10 homepi2 systemd[1]: Mounted POSIX Message Queue File System. Dec 19 23:32:10 homepi2 systemd-modules-load[137]: Inserted module 'i2c_dev' Dec 19 23:32:10 homepi2 systemd[1]: Started Load Kernel Modules. Dec 19 23:32:10 homepi2 systemd[1]: Started Restore / save the current clock. Dec 19 23:32:10 homepi2 systemd[1]: Time has been changed Dec 19 23:32:10 homepi2 systemd[1]: Started udev Coldplug all Devices. Dec 19 23:32:10 homepi2 systemd[1]: Starting Apply Kernel Variables... Dec 19 23:32:10 homepi2 systemd[1]: Mounted FUSE Control File System. Dec 19 23:32:10 homepi2 systemd[1]: Mounting Configuration File System... Dec 19 23:32:10 homepi2 systemd[1]: Started Create Static Device Nodes in /dev. Dec 19 23:32:10 homepi2 systemd[1]: Started Apply Kernel Variables. Dec 19 23:32:10 homepi2 fake-hwclock[133]: Sat Dec 19 14:32:04 UTC 2020 Dec 19 23:32:10 homepi2 systemd-fsck[140]: e2fsck 1.43.3 (04-Sep-2016) Dec 19 23:32:10 homepi2 systemd-fsck[140]: /dev/mmcblk0p2: clean, 101221/959616 files, 1216739/3872384 blocks Dec 19 23:32:10 homepi2 systemd[1]: Starting udev Kernel Device Manager... Dec 19 23:32:10 homepi2 systemd[1]: Starting Remount Root and Kernel File Systems... Dec 19 23:32:10 homepi2 systemd[1]: Started udev Kernel Device Manager. Dec 19 23:32:10 homepi2 systemd[1]: Starting Show Plymouth Boot Screen... Dec 19 23:32:10 homepi2 systemd[1]: Starting Copy rules generated while the root was ro... Dec 19 23:32:10 homepi2 systemd[1]: Starting LSB: MD array assembly... Dec 19 23:32:10 homepi2 systemd[1]: Started Remount Root and Kernel File Systems. Dec 19 23:32:10 homepi2 systemd[1]: Started Copy rules generated while the root was ro. Dec 19 23:32:10 homepi2 systemd[1]: Started Various fixups to make systemd work better on Debian. Dec 19 23:32:10 homepi2 systemd[1]: Starting Local File Systems (Pre). Dec 19 23:32:10 homepi2 systemd[1]: Reached target Local File Systems (Pre). Dec 19 23:32:10 homepi2 systemd[1]: Starting Load/Save Random Seed... Dec 19 23:32:10 homepi2 systemd[1]: Started Load/Save Random Seed. Dec 19 23:32:10 homepi2 systemd[1]: Received SIGRTMIN+20 from PID 179 (plymouthd). Dec 19 23:32:10 homepi2 systemd[1]: Started Show Plymouth Boot Screen. Dec 19 23:32:10 homepi2 systemd[1]: Starting Forward Password Requests to Plymouth Directory Watch. Dec 19 23:32:10 homepi2 systemd[1]: Started Forward Password Requests to Plymouth Directory Watch. Dec 19 23:32:10 homepi2 systemd[1]: Started Dispatch Password Requests to Console Directory Watch. Dec 19 23:32:10 homepi2 systemd[1]: Starting Paths. Dec 19 23:32:10 homepi2 systemd[1]: Reached target Paths. Dec 19 23:32:10 homepi2 systemd[1]: Found device /dev/ttyS0. Dec 19 23:32:10 homepi2 systemd[1]: Found device /dev/mmcblk0p1. Dec 19 23:32:10 homepi2 systemd[1]: Starting File System Check on /dev/mmcblk0p1... Dec 19 23:32:10 homepi2 systemd-fsck[252]: fsck.fat 3.0.27 (2014-11-12) Dec 19 23:32:10 homepi2 systemd-fsck[252]: /dev/mmcblk0p1: 145 files, 2783/8057 clusters Dec 19 23:32:10 homepi2 systemd[1]: Started File System Check on /dev/mmcblk0p1. Dec 19 23:32:10 homepi2 systemd[1]: Mounting /boot... Dec 19 23:32:10 homepi2 systemd[1]: Mounted /boot. Dec 19 23:32:10 homepi2 systemd[1]: Starting Sound Card. Dec 19 23:32:10 homepi2 systemd[1]: Reached target Sound Card. Dec 19 23:32:10 homepi2 systemd[1]: Found device /dev/md6. Dec 19 23:32:10 homepi2 systemd[1]: Starting MD array monitor... Dec 19 23:32:10 homepi2 systemd[1]: Started MD array monitor. Dec 19 23:32:10 homepi2 systemd[1]: Starting File System Check on /dev/md6... Dec 19 23:32:10 homepi2 systemd[1]: Starting system-systemd\x2drfkill.slice. Dec 19 23:32:10 homepi2 systemd[1]: Created slice system-systemd\x2drfkill.slice. Dec 19 23:32:10 homepi2 systemd[1]: Starting Load/Save RF Kill Switch Status of rfkill0... Dec 19 23:32:10 homepi2 systemd-fsck[281]: e2fsck 1.43.3 (04-Sep-2016) Dec 19 23:32:10 homepi2 systemd-fsck[281]: /dev/md6 is in use. Dec 19 23:32:10 homepi2 systemd-fsck[281]: e2fsck: Cannot continue, aborting. Dec 19 23:32:10 homepi2 systemd-fsck[281]: fsck failed with error code 8. Dec 19 23:32:10 homepi2 systemd-fsck[281]: Ignoring error. Dec 19 23:32:10 homepi2 systemd[1]: Started File System Check on /dev/md6. Dec 19 23:32:10 homepi2 systemd[1]: Mounting /mnt/md6... Dec 19 23:32:10 homepi2 systemd[1]: Started Load/Save RF Kill Switch Status of rfkill0. Dec 19 23:32:10 homepi2 mount[288]: mount: /dev/md6 is already mounted or /mnt/md6 busy Dec 19 23:32:10 homepi2 systemd[1]: mnt-md6.mount mount process exited, code=exited status=32 Dec 19 23:32:10 homepi2 systemd[1]: Failed to mount /mnt/md6. Dec 19 23:32:10 homepi2 systemd[1]: Unit mnt-md6.mount entered failed state. Dec 19 23:32:10 homepi2 rsyslogd: [origin software="rsyslogd" swVersion="8.4.2" x-pid="507" x-info="http://www.rsyslog.com"] start Dec 19 23:32:10 homepi2 mdadm-raid[171]: Assembling MD array md6...done (started [4/4]). Dec 19 23:32:10 homepi2 mdadm-raid[171]: Generating udev events for MD arrays...done. Dec 19 23:32:10 homepi2 systemd[1]: Started LSB: MD array assembly. |
何らかの理由で起動時にRAIDボリュームをマウント出来ずに、そのまま稼働していたようです。幸い、Raspberry Piを手動で再起動させると今度はRAIDも問題無く立ち上がり、ストレージの中身も復帰しました。ちなみに正常時のログは以下の通り。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
Dec 24 09:34:16 homepi2 rsyslogd: [origin software="rsyslogd" swVersion="8.4.2" x-pid="507" x-info="http://www.rsyslog.com"] exiting on signal 15. Dec 24 09:34:23 homepi2 rsyslogd: [origin software="rsyslogd" swVersion="8.4.2" x-pid="508" x-info="http://www.rsyslog.com"] start Dec 24 09:34:23 homepi2 systemd[1]: Starting Create Static Device Nodes in /dev... Dec 24 09:34:23 homepi2 systemd-modules-load[139]: Inserted module 'i2c_dev' Dec 24 09:34:23 homepi2 systemd[1]: Started Load Kernel Modules. Dec 24 09:34:23 homepi2 systemd[1]: Started Restore / save the current clock. Dec 24 09:34:23 homepi2 systemd[1]: Time has been changed Dec 24 09:34:23 homepi2 systemd[1]: Started udev Coldplug all Devices. Dec 24 09:34:23 homepi2 systemd[1]: Started Create Static Device Nodes in /dev. Dec 24 09:34:23 homepi2 systemd[1]: Started File System Check on Root Device. Dec 24 09:34:23 homepi2 systemd[1]: Starting Remount Root and Kernel File Systems... Dec 24 09:34:23 homepi2 systemd[1]: Starting udev Kernel Device Manager... Dec 24 09:34:23 homepi2 systemd[1]: Starting Apply Kernel Variables... Dec 24 09:34:23 homepi2 systemd[1]: Mounted FUSE Control File System. Dec 24 09:34:23 homepi2 systemd[1]: Mounting Configuration File System... Dec 24 09:34:23 homepi2 fake-hwclock[133]: Thu Dec 24 00:34:18 UTC 2020 Dec 24 09:34:23 homepi2 systemd-fsck[141]: e2fsck 1.43.3 (04-Sep-2016) Dec 24 09:34:23 homepi2 systemd-fsck[141]: /dev/mmcblk0p2: clean, 101221/959616 files, 1233238/3872384 blocks Dec 24 09:34:23 homepi2 systemd[1]: Mounted Configuration File System. Dec 24 09:34:23 homepi2 systemd[1]: Started udev Kernel Device Manager. Dec 24 09:34:23 homepi2 systemd[1]: Started Remount Root and Kernel File Systems. Dec 24 09:34:23 homepi2 systemd[1]: Started Apply Kernel Variables. Dec 24 09:34:23 homepi2 systemd[1]: Started Various fixups to make systemd work better on Debian. Dec 24 09:34:23 homepi2 systemd[1]: Starting Local File Systems (Pre). Dec 24 09:34:23 homepi2 systemd[1]: Reached target Local File Systems (Pre). Dec 24 09:34:23 homepi2 systemd[1]: Starting Load/Save Random Seed... Dec 24 09:34:23 homepi2 systemd[1]: Starting Show Plymouth Boot Screen... Dec 24 09:34:23 homepi2 systemd[1]: Starting Copy rules generated while the root was ro... Dec 24 09:34:23 homepi2 systemd[1]: Starting LSB: MD array assembly... Dec 24 09:34:23 homepi2 systemd[1]: Started Copy rules generated while the root was ro. Dec 24 09:34:23 homepi2 systemd[1]: Started Load/Save Random Seed. Dec 24 09:34:23 homepi2 systemd[1]: Received SIGRTMIN+20 from PID 195 (plymouthd). Dec 24 09:34:23 homepi2 systemd[1]: Started Show Plymouth Boot Screen. Dec 24 09:34:23 homepi2 systemd[1]: Starting Forward Password Requests to Plymouth Directory Watch. Dec 24 09:34:23 homepi2 systemd[1]: Started Forward Password Requests to Plymouth Directory Watch. Dec 24 09:34:23 homepi2 systemd[1]: Started Dispatch Password Requests to Console Directory Watch. Dec 24 09:34:23 homepi2 systemd[1]: Starting Paths. Dec 24 09:34:23 homepi2 systemd[1]: Reached target Paths. Dec 24 09:34:23 homepi2 systemd[1]: Found device /dev/ttyS0. Dec 24 09:34:23 homepi2 systemd[1]: Found device /dev/mmcblk0p1. Dec 24 09:34:23 homepi2 systemd[1]: Starting Sound Card. Dec 24 09:34:23 homepi2 systemd[1]: Reached target Sound Card. Dec 24 09:34:23 homepi2 systemd[1]: Starting File System Check on /dev/mmcblk0p1... Dec 24 09:34:23 homepi2 systemd-fsck[255]: fsck.fat 3.0.27 (2014-11-12) Dec 24 09:34:23 homepi2 systemd-fsck[255]: /dev/mmcblk0p1: 145 files, 2783/8057 clusters Dec 24 09:34:23 homepi2 systemd[1]: Started File System Check on /dev/mmcblk0p1. Dec 24 09:34:23 homepi2 systemd[1]: Mounting /boot... Dec 24 09:34:23 homepi2 systemd[1]: Mounted /boot. Dec 24 09:34:23 homepi2 systemd[1]: Starting system-systemd\x2drfkill.slice. Dec 24 09:34:23 homepi2 systemd[1]: Created slice system-systemd\x2drfkill.slice. Dec 24 09:34:23 homepi2 systemd[1]: Starting Load/Save RF Kill Switch Status of rfkill0... Dec 24 09:34:23 homepi2 systemd[1]: Started Load/Save RF Kill Switch Status of rfkill0. Dec 24 09:34:23 homepi2 systemd[1]: Starting system-ifup.slice. Dec 24 09:34:23 homepi2 systemd[1]: Created slice system-ifup.slice. Dec 24 09:34:23 homepi2 mdadm-raid[173]: Assembling MD array md6...done (started [4/4]). Dec 24 09:34:23 homepi2 mdadm-raid[173]: Generating udev events for MD arrays...done. Dec 24 09:34:23 homepi2 systemd[1]: Started LSB: MD array assembly. Dec 24 09:34:23 homepi2 systemd[1]: Starting Local File Systems. Dec 24 09:34:23 homepi2 systemd[1]: Reached target Local File Systems. Dec 24 09:34:23 homepi2 systemd[1]: Starting Tell Plymouth To Write Out Runtime Data... Dec 24 09:34:23 homepi2 systemd[1]: Starting Create Volatile Files and Directories... Dec 24 09:34:23 homepi2 systemd[1]: Starting Remote File Systems. Dec 24 09:34:23 homepi2 systemd[1]: Reached target Remote File Systems. Dec 24 09:34:23 homepi2 systemd[1]: Starting Trigger Flushing of Journal to Persistent Storage... Dec 24 09:34:23 homepi2 systemd[1]: Starting LSB: Set console font and keymap... Dec 24 09:34:23 homepi2 systemd[1]: Starting LSB: Switch to ondemand cpu governor (unless shift key is pressed)... Dec 24 09:34:23 homepi2 systemd[1]: Starting LSB: Raise network interfaces.... Dec 24 09:34:23 homepi2 systemd[1]: Started Tell Plymouth To Write Out Runtime Data. Dec 24 09:34:23 homepi2 systemd[1]: Found device /dev/md6. Dec 24 09:34:23 homepi2 raspi-config[298]: Checking if shift key is held down:Error opening '/dev/input/event*': No such file or directory Dec 24 09:34:23 homepi2 systemd[1]: Started Create Volatile Files and Directories. Dec 24 09:34:23 homepi2 raspi-config[298]: No. Switching to ondemand scaling governor. Dec 24 09:34:23 homepi2 systemd[1]: Started LSB: Switch to ondemand cpu governor (unless shift key is pressed). Dec 24 09:34:23 homepi2 systemd[1]: Started Trigger Flushing of Journal to Persistent Storage. Dec 24 09:34:23 homepi2 systemd[1]: Starting Update UTMP about System Boot/Shutdown... Dec 24 09:34:23 homepi2 systemd[1]: Starting MD array monitor... Dec 24 09:34:23 homepi2 systemd[1]: Started MD array monitor. Dec 24 09:34:23 homepi2 systemd[1]: Starting File System Check on /dev/md6... Dec 24 09:34:23 homepi2 systemd-fsck[340]: e2fsck 1.43.3 (04-Sep-2016) Dec 24 09:34:23 homepi2 systemd[1]: Started Update UTMP about System Boot/Shutdown. Dec 24 09:34:23 homepi2 console-setup[297]: Setting up console font and keymap...done. Dec 24 09:34:23 homepi2 systemd[1]: Started LSB: Set console font and keymap. Dec 24 09:34:23 homepi2 networking[299]: Configuring network interfaces...can't add wlan0 to bridge br0: Operation not supported Dec 24 09:34:23 homepi2 networking[299]: Waiting for br0 to get ready (MAXWAIT is 32 seconds). Dec 24 09:34:23 homepi2 systemd-fsck[340]: /dev/md6: clean, 25623/14704640 files, 22510905/58800640 blocks Dec 24 09:34:23 homepi2 systemd[1]: Started File System Check on /dev/md6. Dec 24 09:34:23 homepi2 systemd[1]: Mounting /mnt/md6... Dec 24 09:34:23 homepi2 systemd[1]: Mounted /mnt/md6. |
特に物理的、論理的な欠損は見当たらないので原因究明はここまでとして、今後に備えて以下の2つの対策を講じます。
RAID状態のレポートを毎日発信する
遠隔地のRaspberryPiから定期的に受け取るレポートは、vnstatによる日刊のネットワーク使用量に関する事項のみで、このメールの有無が死活監視になっている程度です。RAIDの健康状態も毎日メールで受け取れるようにしてみます。RAID状態の確認に使うのは普段より使っているこのmdadmコマンドです。更に障害発見時の切り分け用にストレージやUSBデバイス情報も付属しておきます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# mdadm --detail /dev/md6 /dev/md6: Version : 1.2 Creation Time : Mon Aug 10 11:48:32 2020 Raid Level : raid6 Array Size : 235202560 (224.31 GiB 240.85 GB) Used Dev Size : 117601280 (112.15 GiB 120.42 GB) Raid Devices : 4 Total Devices : 4 Persistence : Superblock is persistent Intent Bitmap : Internal Update Time : Mon Dec 28 16:05:12 2020 State : clean Active Devices : 4 Working Devices : 4 Failed Devices : 0 Spare Devices : 0 Layout : left-symmetric Chunk Size : 512K Name : homepi2:6 (local to host homepi2) UUID : XXXXXXXX:XXXXXXXX:XXXXXXXX:XXXXXXXX Events : 7501 Number Major Minor RaidDevice State 5 8 17 0 active sync /dev/sdb1 1 8 1 1 active sync /dev/sda1 4 8 49 2 active sync /dev/sdd1 3 8 33 3 active sync /dev/sdc1 # df -h Filesystem Size Used Avail Use% Mounted on /dev/root 15G 4.6G 9.4G 33% / devtmpfs 481M 0 481M 0% /dev tmpfs 486M 0 486M 0% /dev/shm tmpfs 486M 50M 437M 11% /run tmpfs 5.0M 4.0K 5.0M 1% /run/lock tmpfs 486M 0 486M 0% /sys/fs/cgroup /dev/mmcblk0p1 63M 22M 42M 35% /boot /dev/md6 220G 82G 128G 40% /mnt/md6 # lsusb Bus 001 Device 006: ID 0781:5591 SanDisk Corp. Bus 001 Device 005: ID 0781:5591 SanDisk Corp. Bus 001 Device 004: ID 0781:5591 SanDisk Corp. Bus 001 Device 007: ID 0781:5591 SanDisk Corp. Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub # lsusb -t /: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc_otg/1p, 480M |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/5p, 480M |__ Port 1: Dev 3, If 0, Class=Vendor Specific Class, Driver=smsc95xx, 480M |__ Port 2: Dev 7, If 0, Class=Mass Storage, Driver=usb-storage, 480M |__ Port 3: Dev 4, If 0, Class=Mass Storage, Driver=usb-storage, 480M |__ Port 4: Dev 5, If 0, Class=Mass Storage, Driver=usb-storage, 480M |__ Port 5: Dev 6, If 0, Class=Mass Storage, Driver=usb-storage, 480M |
これを毎朝実行してメール本文に貼り付け送信するタスクをcronに登録します( mdadm 使うので実行者はrootにて)。
1 |
echo "$(/sbin/mdadm --detail /dev/md6 && echo && /bin/df -h && echo && /usr/bin/lsusb && echo && /usr/bin/lsusb -t && echo)" | /usr/bin/mail -s "$(hostname): Daily RAID Report" RECEIPT_EMAIL_ADDR |
尚、このRaspberry Piには以前のRAID障害対策の一環でsSMTPを導入済なので、これだけでメールを送信することが出来ます。
スクリプトファイル化 【2022.04追記】
さすがにcronへ上記の長文ワンライナーを記述するのは何かと不便なので、バッチファイルに書き直します。
その際に mail コマンドには、 -r オプション追記して送信元メールアドレスを明示しています。こうしないとsSMTPの仕様なのか送信元アドレスが、「コマンド実行時のユーザ名@ホストのFQDN(例: pi@raspberrypi.local )」として、送出されてしまうからです。
sSMTPの設定でドメイン部分は変更可能ですが、やはりSPAM判定を避けるためには、実在するメールアドレスから発信されたメールにしておいた方が安心でしょう。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#!/bin/bash ## CHECK HAS INTERNET if ping -c1 -w1 8.8.8.8 > /dev/null 2>&1; then echo "[`date +"%Y/%m/%d(%a) %k:%M:%S"`] WAN ONLINE" else echo "[`date +"%Y/%m/%d(%a) %k:%M:%S"`] WAN OFFLINE, BATCH ABORTED." exit 1 fi ## COLLECT REPORT repo="" repo+=`/sbin/mdadm --detail /dev/md6`"\n\n" repo+=`/bin/df -h`"\n\n" repo+=`/usr/bin/lsusb`"\n\n" repo+=`/usr/bin/lsusb -t` echo "[`date +"%Y/%m/%d(%a) %k:%M:%S"`] RAID REPORT GENERATED;" echo -e "$repo" ## MAIL addrTo="#####@####.com" addrFrom="#####@#######.net" echo "[`date +"%Y/%m/%d(%a) %k:%M:%S"`] SENDING E-MAIL $addrFrom --> $addrTo" echo -e "$repo" | /usr/bin/mail -v -s "$(hostname): Daily RAID Report" -r $addrFrom $addrTo echo "[`date +"%Y/%m/%d(%a) %k:%M:%S"`] BATCH END" |
このスクリプトファイルを実行権限を付与した上で適当な場所へ配置したら、cronには次の要領で呼び出してもらいます( mdadm を扱うのでrootユーザで)。 mail コマンドにはデバッグ用の -v オプションを付けているので、SMTPサーバとのやり取りに問題はないかの判断材料にすることができます。
1 |
/home/pi/raidreportmail.sh > /tmp/raid_email 2>&1 |
RAIDストレージのあるRaspberry Pi側の対策は以上です。次ページでは、このストレージのオフサイトバックアップを担うNAS、Synology DS212j側へ対策を施します。