How to restore missing command history on Mac iTerm

I noticed on my Mac that sometimes my command history gets lost. In researching I came across this article Bash History missing from Terminal

I build this script which I place in my home directory, but it could be any place as long as it is run from the user who lost their command history.  The features are that it will find any commands that are missing from the .bash_history and add them while preserving the order of the existing command history.

$ more restore_history.sh
#!/bin/bash
# Restore missing command history for user
MYUSER=`id -un`
cat /Users/$MYUSER/.bash_sessions/*.history | sort | uniq >> /Users/$MYUSER/.bash_history2

# copy missing command history to bash_history
awk '{if (f==1) { r[$0] } else if (! ($0 in r)) { print $0 } } ' f=1 /Users/$MYUSER/.bash_history f=2 /Users/$MYUSER/.bash_history2 >> .bash_history
rm /Users/$MYUSER/.bash_history2