Created
June 9, 2017 15:19
-
-
Save wjhopper/a69117c02abddd8ad2a3065404ef1969 to your computer and use it in GitHub Desktop.
Cleaning old CCLab Experiment Manager backups
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 | |
## This script is to help clean up the experiment manager backups | |
cd /media/PatricksHD/CC9_Backups | |
touch removal_list.txt | |
# Compressed tarballs of the pydio user data directory are taken twice a day with a cron job | |
# The filenames follow the naming convention pydio_userdata_backup_YYYY-MM-DD_HH-MM.tar.bz | |
# Thus, this script assumes that the date of a backup can be extacted by splitting | |
# the filename on underscores and extracting the fourth field, and that 2 files exist per date. | |
all_dates=$(find . -name 'pydio_userdata_backup*' | cut -d '_' -f 4 | sort -u) | |
# Loops over the dates we found backups for | |
for d in $all_dates; do | |
# Find the names of files that have the current YYYY-MM-DD string in $d in their name | |
x=$(find . -name "*$d*") | |
## If 2 backups from one date are found, proceed to compare them to see if they're identical. | |
# There might not be 2, as older files might have already been deleted | |
if [[ $(echo "$x" | wc -l) = 2 ]]; then | |
# diff only reports when files are differ. Output will be empty when files are the same | |
# -z returns true if the string is null, so this checks if the files are the same | |
# according to diff. | |
# If they are they same, put the first one in the list of files to be deleted | |
if [[ -z $(echo "$x" | xargs -n 2 diff) ]]; then | |
echo $x | cut -d' ' -f 1 >> removal_list.txt | |
fi | |
fi | |
done; | |
# Interactively ask if you want to delete each file | |
for f in $(cat removal_list.txt) ; do | |
rm -i "$f" | |
done | |
rm removal_list.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment