Skip to content

Instantly share code, notes, and snippets.

@mrmuli
Last active August 29, 2018 12:23
Show Gist options
  • Save mrmuli/5a32fff991a382df5d3b41c33042802b to your computer and use it in GitHub Desktop.
Save mrmuli/5a32fff991a382df5d3b41c33042802b to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# this script runs a clean up of files that are older than last 15 days
# command to get files older by x numer of days
# update the bucket and target_location variables to your required destination
## vars ##
s3bucket=your-bucket-name-here
target_location=directory-with-target-work
AWS_="$(which aws)"
sendToS3OrExit(){
local location=$target_location
local bucket=$s3bucket
local AWS=AWS_
cd $target_location
for i in $(find . -mtime +15);
do
$($AWS s3 cp $i $bucket)
rc=$?;
if [[ $rc != 0 ]] ; then
echo "failed to copy $(i)"
exit $rc;
else
find . -type f -o -name $i -exec rm {} \;
echo "cleaning done"
fi
done
}
# the function below will delete all data that is older than 15 days
#####
####
###
## NOTE: THERE IS NO COMEBACK FROM THIS ##
#uncomment the last line to execute, make sure the sendToS3OrExit call is commented out.
deleteByDate(){
local location=$target_location
cd $location
find . -mtime +15 -exec rm {} \;
}
sendToS3OrExit
#deleteByDate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment