Skip to content

Instantly share code, notes, and snippets.

@theY4Kman
Created April 9, 2011 05:41
Show Gist options
  • Save theY4Kman/911173 to your computer and use it in GitHub Desktop.
Save theY4Kman/911173 to your computer and use it in GitHub Desktop.
Compresses each folder in data/sets and places its tar.gz in data/sets/archives
#!/bin/bash
pushd data/sets/ > /dev/null
mkdir -p data/sets/
mkdir -p archives
find . -maxdepth 1 -mindepth 1 -type d -not -name archives -not -name data | while read -r set
do
export set set=`basename $set`
touch -d "`find $set -exec stat \{} --printf="%y\n" \; | sort -n -r | head -1`" ${set}test
if [ ${set}test -nt archives/$set.tar.gz ]
then
ln -sd `pwd`/$set data/sets/$set
tar -chvf archives/$set.tar.gz data/ > /dev/null
echo "Compressed dataset \"$set\" to data/sets/archives/$set.tar.gz"
rm data/sets/$set
else
echo "$set.tar.gz up to date!"
fi
rm ${set}test
done
rm -rf data
popd > /dev/null
echo "Complete!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment