Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
releases_path=/data/sites/yoursite.com/releases # change this
keep_releases=5
versions=`ls -xt $releases_path`
releases=(${versions// / })
# check available number of versions in releases directory
releases_count=${#releases[@]}
if [ $releases_count -le $keep_releases ]
then
echo 'no old releases to clean up'
else
echo keeping $keep_releases of $releases_count deployed releases
releases=(${releases[@]:0:0} ${releases[@]:($keep_releases)})
for release in "${releases[@]}"
do
path=$releases_path$release
`rm -rf $path`
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment