@@ -149,8 +149,9 @@ exec > /tmp/splunkconf-backup-debug.log 2>&1
149149# 20251007 move init delay after variable initialization just before backups
150150# 20251007 fix regression on BACKUPSTATE and BACKUPKV flag support to disable specific backups
151151# 20251215 remove version check for kvdump, assuming always version at minimum 7.1
152+ # 20251215 add timeout for curl command to speed up backup for on prem with firewalls
152153
153- VERSION=" 20251215a "
154+ VERSION=" 20251215b "
154155
155156# ##### BEGIN default parameters
156157# dont change here, use the configuration file to override them
@@ -189,6 +190,10 @@ umask 027
189190# group can access backup (should be splunk group)
190191# other should not access backups
191192
193+ # set timeout to avoid very long timeout when calling curl to autodetect AWS (for on prem with firewalls droping it)
194+ CURLCONNECTTIMEOUT=10
195+ CURLMAXTIME=60
196+
192197# we always do relative backup but if ever you want the old way, change mode below to abs
193198# recovery part support both mode
194199# du to recent tar behavior related to exclusion it is better to use rel mode
@@ -453,11 +458,11 @@ function check_cloud() {
453458 # but this is almost certainly overkill for this purpose (and the above
454459 # checks of "EC2" prefixes have a higher false positive potential, anyway).
455460 # imdsv2 support : TOKEN should exist if inside AWS even if not enforced
456- TOKEN=` curl --silent --show-error -X PUT " http://169.254.169.254/latest/api/token" -H " X-aws-ec2-metadata-token-ttl-seconds: 900" `
461+ TOKEN=` curl --silent --show-error --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME - X PUT " http://169.254.169.254/latest/api/token" -H " X-aws-ec2-metadata-token-ttl-seconds: 900" `
457462 if [ -z ${TOKEN+x} ]; then
458463 # TOKEN NOT SET , NOT inside AWS
459464 cloud_type=0
460- elif $( curl --silent -m 5 -H " X-aws-ec2-metadata-token: $TOKEN " http://169.254.169.254/latest/dynamic/instance-identity/document | grep -q availabilityZone) ; then
465+ elif $( curl --silent -m 5 --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME - H " X-aws-ec2-metadata-token: $TOKEN " http://169.254.169.254/latest/dynamic/instance-identity/document | grep -q availabilityZone) ; then
461466 debug_log ' AWS instance detected'
462467 cloud_type=1
463468 fi
@@ -989,10 +994,10 @@ if [ $CHECK -ne 0 ]; then
989994 if [[ " cloud_type" -eq 1 ]]; then
990995 # aws
991996 # setting up token (IMDSv2)
992- TOKEN=` curl --silent --show-error -X PUT " http://169.254.169.254/latest/api/token" -H " X-aws-ec2-metadata-token-ttl-seconds: 900" `
997+ TOKEN=` curl --silent --show-error --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME - X PUT " http://169.254.169.254/latest/api/token" -H " X-aws-ec2-metadata-token-ttl-seconds: 900" `
993998 # lets get the s3splunkinstall from instance tags
994- INSTANCE_ID=` curl --silent --show-error -H " X-aws-ec2-metadata-token: $TOKEN " http://169.254.169.254/latest/meta-data/instance-id `
995- REGION=` curl --silent --show-error -H " X-aws-ec2-metadata-token: $TOKEN " http://169.254.169.254/latest/meta-data/placement/availability-zone | sed ' s/.$//' `
999+ INSTANCE_ID=` curl --silent --show-error --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME - H " X-aws-ec2-metadata-token: $TOKEN " http://169.254.169.254/latest/meta-data/instance-id `
1000+ REGION=` curl --silent --show-error --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME - H " X-aws-ec2-metadata-token: $TOKEN " http://169.254.169.254/latest/meta-data/placement/availability-zone | sed ' s/.$//' `
9961001
9971002 # we put store tags in instance-tags file-> we will use this later on
9981003 aws ec2 describe-tags --region $REGION --filter " Name=resource-id,Values=$INSTANCE_ID " --output=text | sed -e ' s/^[[:space:]]*//' -e ' s/[[:space:]]*$//' -e ' s/[[:space:]]*=[[:space:]]*/=/' | sed -r ' s/TAGS\t(.*)\t.*\t.*\t(.*)/\1="\2"/' | grep -E " ^splunk" > $INSTANCEFILE
0 commit comments