NETGEAR is aware of a growing number of phone and online scams. To learn how to stay safe click here.

Forum Discussion

Sandshark's avatar
Sandshark
Sensei - Experienced User
Dec 24, 2020

Script for making remote NAS diagnostics available locally

StephenB suggested starting this.  Obviously, it's for advanved users with at least some Linux experience.

 

I have one main NAS, two local backup NAS, and a remote backup NAS.  Since the backup devices are not on all the time, I have a script I run that creates some diagnostic data files and then RSYNC's them to my main NAS.  That lets me review the status of those NAS without having to turn them on.  For the remote NAS, I use ZeroTier so all I have to do is a normal rsync to the main NAS's ZeroTier IP.  If somebody wants to add details for rsync over SSH instead, please do.

 

This is for local backup NAS "RN4200B" and my main NAS is located at 192.168.0.42:

#!/bin/sh
date >/data/hdsentinel/hdinfo_RN4200B.txt
echo >>/data/hdsentinel/hdinfo_RN4200B.txt
/apps/hdsentinel/HDSentinel -solid >>/data/hdsentinel/hdinfo_RN4200B.txt
echo  >>/data/hdsentinel/hdinfo_RN4200B.txt
rnutil get_disk_info >>/data/hdsentinel/hdinfo_RN4200B.txt
/apps/hdsentinel/HDSentinel -r /data/hdsentinel/hdsreport_RN4200B.html -html
rnutil create_system_log -o /data/hdsentinel/log_RN4200B.zip
rsync -a /data/hdsentinel/* rsync://192.168.0.42/hdsentinel

 

I use HDSentinel (Linux version is free) and the Netgear program rnutil to do this.  The shares in question have rsync enabled, of course.  I run get_disk_info separately just for convenience, the result is the same as in the log zip.  I run something similar on my main NAS and have a regular backup job that copies all the local and remote data to a backup so i can get to it if the main NAS crashes.  Just make sure it doesn't copy to the same directory as is used for the local data on that backup, or you'll create a vicious loop (unless you time stamp, as shown below).  I could have added the rsync to the script to make sure I'm getting the latest copy on the backup right away, but I didn't bother.

 

This will overwrite each time.  If you want to change that, just add a time/date stamp to the file name as in the following example:

rnutil create_system_log -o /data/hdsentinel/log_RN4200B_$(date +%Y%m%d%H%M%S).zip

 

Of course, now those will begin to stack up, so you can create another script to trim them (every 5 days in the following example) and run it on the NAS that collects the files, or just add to the script already collecting the data for the main NAS:

#!/bin/sh
find /data/hdsentinel/* -mtime +5 -exec rm {} \;

 

Then, put them in the appropriate /etc/cron.xxx directory and set them to executable.  I put the backup NAS script in cron.hourly to insure it runs each time the unit powers on.  Sometimes, that does mean you'd get more than one (especially during a scrub).  I recommend you run them manually as a test before putting them in the cron directory.

 

There may be some other commands that could be useful here that others may want to suggest.

5 Replies

  • StephenB's avatar
    StephenB
    Guru - Experienced User

    I haven't installed hdsentinal, so I'll need to take a look at that.

     

    You can get quite a bit of info with smartctl (including stuff that isn't in the log zip), and I was thinking about using that.

     

    This gives you a lot of info on the installed disks:

    for i in a b c d e f g h i j k l m n; do smartctl -a -x -l defects /dev/sd${i} | egrep -v "local build|No such device|smartmontools"; done >>smart.log

     

    Though if you want to be more selective on the smart stats you can also do something like

    for i in a b c d e f g h i j k l m n; do smartctl -a /dev/sd${i} | egrep -i "Device Model|Serial Number|Reallocated_sec|ATA Er|offline_uncorrect|current_pending_sector|Power_on"; done >>smart.log

    tailoring the egrep string to include the specific parameters you want to track.  mdgm suggested this version to me a few years ago now (it is also handy in tech support mode).

     

    • Sandshark's avatar
      Sandshark
      Sensei - Experienced User

      StephenB wrote:

      I haven't installed hdsentinal, so I'll need to take a look at that.

      I find it to be quite helpful.  While I'm sure you can get the same information from smartctl (and more, as it does not show a completely missing drive as your command does), it has a very noce presentation.  It's designed to be monitored by a PC running a (paid) version, but it works stand-alone just fine.  The line with HDSentinel -solid gives a very brief overview and then HDSentinel -r -html gives a much more detailed report.  It's especially useful to me on my main 12-drive NAS and 24-drive (not yet full) external chassis, especially since the external has SAS drives in it.  But I sill recommend you take a look.

       

      HDSentinel does have a shortcoming that it only reports use on one partition.  That turns out to be the system partition on a ReadyNAS.  And while it would be nice to have a report on all partitions, a report on the one that the GUI does not report and can cause catastrophy if it fills is nice.

      • StephenB's avatar
        StephenB
        Guru - Experienced User

        I downloaded it, and have it on my main NAS and one of the backup ones.  It does look useful.

         

        I've developed a starting point for my own script.  That script will use rnutil to make the system log on OS 6 systems, otherwise it will zip /var/logs.  It will then run smartctl, and will run HDSentinel if it is present. The logs are stored on a local NAS share, and if the NAS is a backup it will also rsync to the main NAS.  It should also be possible to combine this with rsync backup jobs (backing up the main share to the local log share).

         

        I still need to test it on one of my 4.1.16 systems, and also I still need to test retention.  Though I'm thinking I won't need retention in the script, I can simply delete old files from time to time on the main NAS, and the rsync backups will propagate the deletions to the backups.

NETGEAR Academy

Boost your skills with the Netgear Academy - Get trained, certified and stay ahead with the latest Netgear technology! 

Join Us!

ProSupport for Business

Comprehensive support plans for maximum network uptime and business peace of mind.

 

Learn More