Created
June 26, 2023 16:15
-
-
Save zuf/e4ea27b10b1260b42df8830e326cf5f3 to your computer and use it in GitHub Desktop.
Simple bash history auto backup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# copy to your .bashrc to keey bash history backups at ~/bak/bash/history/ | |
# backup bash history when start new bash session and there no bak files for last 5 minutes | |
LAST_HIST_BAKS=$(find $HOME/bak/bash/history/ -type f -mmin -5) | |
if [ -z "$LAST_HIST_BAKS" ]; then | |
mkdir -p $HOME/bak/bash/history/ | |
zstd < $HOME/.bash_history > $HOME/bak/bash/history/bash_history.$(date +%Y-%m-%d_%H-%M-%S.%N).zst | |
# remove old (older then 30 days) bak files | |
find ~/bak/bash/history/ -type f -mtime '+30' | xargs --no-run-if-empty rm | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment