Skip to content

Instantly share code, notes, and snippets.

@stoyanovgeorge
Last active August 20, 2018 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stoyanovgeorge/71d6e453376706a67944dfa70622783d to your computer and use it in GitHub Desktop.
Save stoyanovgeorge/71d6e453376706a67944dfa70622783d to your computer and use it in GitHub Desktop.
Backup files from $HOME/backup directory and
#!/bin/bash
bkp_dir="$HOME/backup"
now="$(date +'%Y%m%d')"
tar cfJ $HOME/backup/"${now}"_scripts.tar.xz "$HOME"/scripts/ &> /dev/null
# Evaluates the md5sum of the most recent backup and compares its md5sum against the other files in the same directory. If the md5sum is the same removes the duplicated file
md5sum_now=$(md5sum "$bkp_dir"/"${now}"_scripts.tar.xz | awk '{ print $1 }')
for filename in $bkp_dir/*.tar.xz;
do
if [[ "$md5sum_now" == $(md5sum "$filename" | awk '{ print $1 }') ]] && [[ "$filename" != "$bkp_dir"/"${now}"_scripts.tar.xz ]]
then
rm "$filename"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment