Getting Data In

Shell script or python to to delete older than 6 months frozen data ?

splunkreal
Motivator

Hello guys,

Would you have an example of shell script or python to to delete older than 6 months frozen data?

Our frozen data is for example in /var/splunk/frozen (it should delete recursively all files older than 6 months)

Thanks in advance.

* If this helps, please upvote or accept solution 🙂 *
0 Karma

Richfez
SplunkTrust
SplunkTrust

realsplunk,

For frozen data you can just not use a cold-to-frozen script of directory - by default frozen is deleted and that will resolve your problem going forward. You can search the indexes.conf documentation for "frozen" and get the options that can be set.

Now that you have Frozen files that are older than what you want to retain, this becomes a simple bash/sh script that just runs a single command on the filesystem. Google can give you a more thorough answer than we can provide here - the first few returned hits in this search all do what you need. Obviously test each and adjust to your needs.

Happy Splunking!
-Rich

splunkreal
Motivator

Thanks, I've started this :

*#!/bin/bash

$1 = first arg : main directory

curDateEpo=date +%s;
beforeDateEpo=expr $curDateEpo - 15768000
echo "Current Epoch time: $curDateEpo";
echo "Before 6 months : $beforeDateEpo";
for i in $(find $1 -maxdepth 1 -type d)
do

echo "file $i : ";

printf "\r";

read latest earliest <<<${i//[^0-9]/ };
earliest=${earliest:0:10}
if [ "$earliest" != "" ]
then
earliestH=date -d @$earliest;
# Compare
if [ "$earliest" -lt "$beforeDateEpo" ]
then
echo "$i older";
echo $earliestH;
fi
fi
done*

* If this helps, please upvote or accept solution 🙂 *
0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...