Last active
August 20, 2018 10:45
-
-
Save stoyanovgeorge/71d6e453376706a67944dfa70622783d to your computer and use it in GitHub Desktop.
Backup files from $HOME/backup directory and
This file contains 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
#!/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