Scrubbing your HDD/SSD data to mitigate bitrot (without 3rd party software)

Note: Excuse me if this post appears mirrored. I could not fix it, but you can try pressing Ctrl+Shift+X or Ctrl+Alt+X and hope that your browser switches the page’s reading-direction.

Bitrot is a real threat, regardless of what storage media is being used. And while some file systems (e.g. ReFS, ZFS) implement automatic measures to protect against bitrot, they might not be readily available, or implementing them could mean too much technical knowledge or work than one can afford.

Besides, self-healing or resilient file systems aren’t practical for certain types of storage media, such as USB drives (containing flash banks or HDDs).

For the unprotected file systems, one can only cross their fingers and hope that the data will keep its integrity. However, there are applications out there that do a raw data read to help the drive detect and correct any potential or partial read errors before they become permanent. The work principle is pretty simple, the program just asks for the contents of the file. The drive contains the error-correction mechanisms in case some data block has correctable errors.

I personally prefer to do this kind of check on my portable drives without using any exotic tools. On Windows (while the performance is not great this is a quick and easy way), I just open a command prompt with administrator privileges, and issue the following instructions (for scrubbing drive D:), which cause the system to read all files in the current directory and its sub-directories recursively, sending the output from this read operation to the NUL special device, effectively not outputting anything to the screen other than the file name:

D:
CD \
FOR /r %i IN (*) DO TYPE "%i" > NUL
Drive read activity

On Linux I use the dd command to read the whole drive or partition.
Assuming the partition is /dev/sdb2 (you can use lsblk to list all block devices and their partitions), this is the command:

dd if=/dev/sdb2 of=/dev/null status=progress bs=16K conv=noerror

There must be a better way on Linux to check only the files, not the whole partition, but I really didn’t get to need to do it that much, so I’m leaving it here.

الإعلان

How to fix: Unexpected duplicate entries found in events4.nsf

 

Some times after you upgrade the Domino server, you might occasionally see this error message in the console:

Diagnostics on view ($Messages) of database events4.nsf was aborted: Unexpected duplicate entries found.

Which basically indicates that there are some Event Messages sharing the same Event ID.

This can happen because some Event Messages might have been updated in the events4 template shipped with the new version, and when these updated messages are copied to the old database, the old message may get left over for one reason or another. In one case I found that the Event ID had different capitalization in the duplicate documents.

Regardless of the reason, you want to clean the duplicates up. The first thing to try is to let the Event task take care of it by issuing the command:

tell event clean ($Messages)

If the error message you’re receiving is about an issue in a different view, you can change the view name in this command. Basically the syntax is:

tell event clean <view name>

If this does not solve your issue, you can write a simple Agent that scans the affected view directly. To do so:

  1. Open the events4.nsf database in the Domino Designer.
  2. Create a new Agent (Lotus Script). Name it: Detect $Messages duplicates
  3. Use the following code, which checks for duplicates in the ($Messages) view.
  4. Change the Agent Trigger to “Actions Menu”, and the Target to “None”. Then save it.
  5. Run the Agent from the Notes Client.

Here’s the code:

Sub Initialize
 Dim s As New NotesSession
 Dim db As NotesDatabase
 Dim v As NotesView
 Dim doc As NotesDocument

 Set db = s.CurrentDatabase
 Set v = db.GetView("($Messages)")
 Call v.Refresh()
 v.AutoUpdate = False

 Set doc = v.GetFirstDocument()

 Dim dc As NotesDocumentCollection
 Dim ID As String

 Do Until doc Is Nothing
   ID = doc.GetItemValue("Value")(0)
   Set dc = v.GetAllDocumentsByKey(ID, True)
   
   If dc.Count > 1 Then
     Print "Message with ID: " & ID & " is duplicated."
     MsgBox "Message with ID: " & ID & " is duplicated. No more processing will be done. Additioanl duplicates may exist."
     Exit sub
   End If

   Set doc = v.GetNextDocument(doc)
 Loop

 MsgBox "No duplicates found."
 Print "No duplicates found."
End Sub

When run, this Agent will show a message box with the Event ID of the first duplicate Event Message it encounters.

To resolve the duplication, in the Notes Client, while the events4 database is open, open the View menu, hold down Ctrl+Shift, and click Go To…

Select the ($Messages) view from the list to open this view, and then search for the Event ID.

It’s up to you to decide how to resolve the duplication. Basically you can just review the documents, then decide to keep one of them and delete the other. If you are not sure, check the creation & modification times of the documents. You can also check the same ID in the template events4.ntf.. In this case, you might as well just delete all of the Event Messages and copy them from the Template. However, I have not tested whether this could cause any undesired side effects, so you may want to test with it after taking a backup.