Deployment Architecture

Automate Splunk configuration files backup on day basis

splunkwar
Explorer

Hi,

I'd like to automate Splunk config files backup process for every 24 hours.

Is there any Apps/Scripts available to achieve the same.

Many thanks.

1 Solution

manjunathmeti
Champion

You can compress $SPLUNK_HOME/etc/ and keep backup of compressed file. A simple shell script can do this and you can schedule it for every 24 hours using cron.

/backup.sh

#!/bin/bash
TIME=`date +%b-%d-%y`                      # This Command will read the date.
FILENAME=splunk-configs-backup-$TIME.tar.gz    # The filename including the date.
SRCDIR=/opt/splunk/etc                       # Source backup folder.
DESDIR=/backup                                    # Destination of backup file.
tar -cpzf $DESDIR/$FILENAME $SRCDIR

Cron expression:

00 04 * * * /bin/bash /backup.sh

This will run the script every day at 04:00:00.

View solution in original post

manjunathmeti
Champion

You can compress $SPLUNK_HOME/etc/ and keep backup of compressed file. A simple shell script can do this and you can schedule it for every 24 hours using cron.

/backup.sh

#!/bin/bash
TIME=`date +%b-%d-%y`                      # This Command will read the date.
FILENAME=splunk-configs-backup-$TIME.tar.gz    # The filename including the date.
SRCDIR=/opt/splunk/etc                       # Source backup folder.
DESDIR=/backup                                    # Destination of backup file.
tar -cpzf $DESDIR/$FILENAME $SRCDIR

Cron expression:

00 04 * * * /bin/bash /backup.sh

This will run the script every day at 04:00:00.

SamHTexas
Builder

Which Splunk Server do I run this script, where should be the place / path for this script to run ?

Tags (1)
0 Karma

SamHTexas
Builder

How do I add the cron expression to the stanza please for it to run every 24 hours on weekends for examples. Thank u

Tags (1)
0 Karma

splunkwar
Explorer

Hi, Thanks for the answer.
I have python script, which will do the same. could you please tell me , where should I add this script (directory) & how would I schedule to run for every 24 hours ?
Thanks in advance!

0 Karma

manjunathmeti
Champion

You can copy this script on /opt/splunk/bin/scripts and make it executable and add cron expression in crontab.

# chmod +x /opt/splunk/bin/scripts/test.py
# crontab -e

0 0 * * * /usr/bin/python /opt/splunk/bin/scripts/test.py

Save it. This will trigger this script everyday at midnight.

0 Karma

splunkwar
Explorer

Thanks a lot 🙂

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 ...