@@ -161,8 +161,9 @@ exec > /tmp/splunkconf-backup-debug.log 2>&1
161161# 20260326 add test entry in kvstore collection so it can be used for testing
162162# 20260330 add check for postgres
163163# 20260403 use different location for pgpass on splunk 10.0
164+ # 20260404 add backup pg code block + fix multiple typos
164165
165- VERSION=" 20260403a "
166+ VERSION=" 20260404a "
166167
167168# ##### BEGIN default parameters
168169# dont change here, use the configuration file to override them
@@ -462,7 +463,7 @@ function check_cloud() {
462463 fi
463464 fi
464465 # if detection not yet successfull, try fallback method
465- if [[ $cloud_type -eq " 0 " ]]; then
466+ if [[ " $cloud_type " -eq 0 ]]; then
466467 # Fallback check of http://169.254.169.254/. If we wanted to be REALLY
467468 # authoritative, we could follow Amazon's suggestions for cryptographically
468469 # verifying their signature, see here:
@@ -690,7 +691,7 @@ function do_remote_copy() {
690691 if [ $RES -eq 0 ]; then
691692 result=" success"
692693 echo_log " action=backup type=${TYPE} object=${OBJECT} result=success src=${LFIC} dest=${RFIC} durationms=${DURATION} size=${FILESIZE} ${S3ENDPOINTLOGMESSAGE} ATTEMPT=$ATTEMPT MAXTRY=$REMOTECOPYRETRY "
693- if [[ " cloud_type" -eq 1 ]]; then
694+ if [[ " $ cloud_type" -eq 1 ]]; then
694695 # AWS
695696 if [ " ${REMOTEOBJECTSTORETAGS3} " = " 1" ] && [ " ${REMOTETECHNO} " = " 2" ]; then
696697 debug_log " setting tag via aws ${S3ENDPOINTOPTION} s3api put-object-tagging --bucket ${s3backupbucket} --key ${SRFIC} --tagging ${S3TAGS} "
@@ -825,7 +826,7 @@ function check_assist () {
825826
826827
827828 else
828- debug_log " assist.conf check, inconsistency=$INCONSISTENTi (fine), FI1=$FI1 , FI2= $FI2 " ;
829+ debug_log " assist.conf check, inconsistency=$INCONSISTENT (fine), FI1=$FI1 " ;
829830
830831 fi
831832
@@ -906,7 +907,7 @@ if [ "${MODE}" == "init" ]; then
906907 debug_log " running in init mode, setting up lock to prevent concurrent backup at init"
907908 MODE=" 0"
908909 INIT=1
909- ` touch ${SPLUNK_HOME} /var/run/splunkconf-init.lock`
910+ touch ${SPLUNK_HOME} /var/run/splunkconf-init.lock
910911fi
911912debug_log " splunkconf-backup running with MODE=${MODE} and INIT=${INIT} "
912913
10141015
10151016INSTANCEFILE=" ${SPLUNK_HOME} /var/run/splunk/instance-tags"
10161017if [ $CHECK -ne 0 ]; then
1017- if [[ " cloud_type" -eq 1 ]]; then
1018+ if [[ " $ cloud_type" -eq 1 ]]; then
10181019 # aws
10191020 # setting up token (IMDSv2)
10201021 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" `
@@ -1032,36 +1033,35 @@ if [ $CHECK -ne 0 ]; then
10321033 debug_log " splunk prefixed tags not found, reverting to full tag inclusion (file=$INSTANCEFILE )"
10331034 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"/' > $INSTANCEFILE
10341035 fi
1036+ elif [[ " $cloud_type " -eq 2 ]]; then
1037+ # GCP
1038+ splunkinstanceType=` curl --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME -H " Metadata-Flavor: Google" -fs http://metadata/computeMetadata/v1/instance/attributes/splunkinstanceType`
1039+ if [ -z ${splunkinstanceType+x} ]; then
1040+ debug_log " GCP : Missing splunkinstanceType in instance metadata"
1041+ else
1042+ # > to overwrite any old file here (upgrade case)
1043+ echo -e " splunkinstanceType=${splunkinstanceType} \n" > $INSTANCEFILE
1044+ fi
1045+ splunks3installbucket=` curl --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME -H " Metadata-Flavor: Google" -fs http://metadata/computeMetadata/v1/instance/attributes/splunks3installbucket`
1046+ if [ -z ${splunks3installbucket+x} ]; then
1047+ debug_log " GCP : Missing splunks3installbucket in instance metadata"
1048+ else
1049+ echo -e " splunks3installbucket=${splunks3installbucket} \n" >> $INSTANCEFILE
1050+ fi
1051+ splunks3backupbucket=` curl --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME -H " Metadata-Flavor: Google" -fs http://metadata/computeMetadata/v1/instance/attributes/splunks3backupbucket`
1052+ if [ -z ${splunks3backupbucket+x} ]; then
1053+ debug_log " GCP : Missing splunks3backupbucket in instance metadata"
1054+ else
1055+ echo -e " splunks3backupbucket=${splunks3backupbucket} \n" >> $INSTANCEFILE
1056+ fi
1057+ splunks3databucket=` curl --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME -H " Metadata-Flavor: Google" -fs http://metadata/computeMetadata/v1/instance/attributes/splunks3databucket`
1058+ if [ -z ${splunks3databucket+x} ]; then
1059+ debug_log " GCP : Missing splunks3databucket in instance metadata"
1060+ else
1061+ echo -e " splunks3databucket=${splunks3databucket} \n" >> $INSTANCEFILE
1062+ fi
1063+ splunks3endpointurl=` curl --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME -H " Metadata-Flavor: Google" -fs http://metadata/computeMetadata/v1/instance/attributes/splunks3endpointurl`
10351064 fi
1036- elif [[ " cloud_type" -eq 2 ]]; then
1037- # GCP
1038- splunkinstanceType=` curl --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME -H " Metadata-Flavor: Google" -fs http://metadata/computeMetadata/v1/instance/attributes/splunkinstanceType`
1039- if [ -z ${splunkinstanceType+x} ]; then
1040- debug_log " GCP : Missing splunkinstanceType in instance metadata"
1041- else
1042- # > to overwrite any old file here (upgrade case)
1043- echo -e " splunkinstanceType=${splunkinstanceType} \n" > $INSTANCEFILE
1044- fi
1045- splunks3installbucket=` curl --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME -H " Metadata-Flavor: Google" -fs http://metadata/computeMetadata/v1/instance/attributes/splunks3installbucket`
1046- if [ -z ${splunks3installbucket+x} ]; then
1047- debug_log " GCP : Missing splunks3installbucket in instance metadata"
1048- else
1049- echo -e " splunks3installbucket=${splunks3installbucket} \n" >> $INSTANCEFILE
1050- fi
1051- splunks3backupbucket=` curl --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME -H " Metadata-Flavor: Google" -fs http://metadata/computeMetadata/v1/instance/attributes/splunks3backupbucket`
1052- if [ -z ${splunks3backupbucket+x} ]; then
1053- debug_log " GCP : Missing splunks3backupbucket in instance metadata"
1054- else
1055- echo -e " splunks3backupbucket=${splunks3backupbucket} \n" >> $INSTANCEFILE
1056- fi
1057- splunks3databucket=` curl --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME -H " Metadata-Flavor: Google" -fs http://metadata/computeMetadata/v1/instance/attributes/splunks3databucket`
1058- if [ -z ${splunks3databucket+x} ]; then
1059- debug_log " GCP : Missing splunks3databucket in instance metadata"
1060- else
1061- echo -e " splunks3databucket=${splunks3databucket} \n" >> $INSTANCEFILE
1062- fi
1063- splunks3endpointurl=` curl --connect-timeout $CURLCONNECTTIMEOUT --max-time $CURLMAXTIME -H " Metadata-Flavor: Google" -fs http://metadata/computeMetadata/v1/instance/attributes/splunks3endpointurl`
1064-
10651065else
10661066 warn_log " aws cloud tag detection disabled (missing commands)"
10671067fi
@@ -1220,7 +1220,7 @@ if [ -z ${splunks3backupbucket+x} ]; then
12201220 elif [ " ${REMOTEOBJECTSTOREBUCKET} " != " auto" ]; then
12211221 # REMOTEOBJECTSTOREBUCKET is set lets use this
12221222 s3backupbucket=$REMOTEOBJECTSTOREBUCKET
1223- if [[ " cloud_type" -eq 2 ]]; then
1223+ if [[ " $ cloud_type" -eq 2 ]]; then
12241224 # GCP
12251225 debug_log " name=splunks3backupbucket src=instancetags result=set value='$s3backupbucket ' splunkprefix=false" ;
12261226 # we already have the scheme in var for gcp
@@ -1242,7 +1242,7 @@ if [ -z ${splunks3backupbucket+x} ]; then
12421242 debug_log " remote techno=3 and running in cloud , not using tags"
12431243 elif (( REMOTETECHNO == 4 )) ; then
12441244 debug_log " remote techno=4 and running in cloud , not using tags"
1245- elif [[ " cloud_type" -eq 2 ]]; then
1245+ elif [[ " $ cloud_type" -eq 2 ]]; then
12461246 # GCP
12471247 debug_log " name=splunks3backupbucket src=instancetags result=set value='$s3backupbucket ' splunkprefix=false" ;
12481248 # we already have the scheme in var for gcp
@@ -1264,7 +1264,7 @@ else
12641264 debug_log " remote techno=3 and running in cloud , not using tags"
12651265 elif (( REMOTETECHNO == 4 )) ; then
12661266 debug_log " remote techno=4 , not using tags"
1267- elif [[ " cloud_type" -eq 2 ]]; then
1267+ elif [[ " $ cloud_type" -eq 2 ]]; then
12681268 # GCP
12691269 debug_log " name=splunks3backupbucket src=instancetags result=set value='$s3backupbucket ' splunkprefix=true" ;
12701270 # we already have the scheme in var for gcp
@@ -1488,7 +1488,7 @@ if [ "$MODE" == "0" ] || [ "$MODE" == "scripts" ]; then
14881488 # debug_log "start to backup scripts";
14891489 if [ ${LOCALTYPE} -eq 2 ]; then
14901490 FIC=" ${LOCALBACKUPDIR} /backupconfsplunk-${extmode} scripts-${INSTANCE} .tar.${EXTENSION} " ;
1491- ESS1 =" backuptype=scriptstargetedinstanceoverwrite " ;
1491+ MESS1 =" backuptype=scriptstargetedinstanceoverwrite " ;
14921492 elif [ ${LOCALTYPE} -eq 3 ]; then
14931493 FIC=" ${LOCALBACKUPDIR} /backupconfsplunk-${extmode} scripts.tar.${EXTENSION} " ;
14941494 MESS1=" backuptype=scriptstargetednoinstanceoverwrite " ;
@@ -1518,15 +1518,15 @@ if [ "$MODE" == "0" ] || [ "$MODE" == "scripts" ]; then
15181518 LIS=` ls ${backuptardir} /$i | wc -l`
15191519 if (( $LIS > 0 )) ; then
15201520 debug_log " fileverif : $i exist and not empty"
1521- FILELIST2=" ${STATELIST2 } $i "
1521+ FILELIST2=" ${FILELIST2 } $i "
15221522 else
15231523 debug_log " fileverif : $i exist and empty, not adding it"
15241524 fi
15251525 else
15261526 debug_log " fileverif : $i NOT exist"
15271527 fi
15281528 done
1529- debug_log " FILELIST=${STATELIST } FILELIST2=${FILELIST2} "
1529+ debug_log " FILELIST=${FILELIST } FILELIST2=${FILELIST2} "
15301530 if [ ! -z " ${FILELIST2} " ]; then
15311531
15321532 # tar -zcf ${FIC} ${FILELIST} && echo_log "action=backup type=$TYPE object=${OBJECT} result=success dest=$FIC ${MESS1} " || warn_log "action=backup type=$TYPE object=${OBJECT} result=failure dest=$FIC reason="tar" ${MESS1} please investigate"
@@ -1867,7 +1867,7 @@ pg_done=0
18671867LFICSTATE=" disabled"
18681868OBJECT=" pg"
18691869debug_log " before pg test reached. MODE=${MODE} ."
1870- if [ " $MODE " == " 0" ] || [ " $MODE " == " pg" ]; then
1870+ if [[ " $MODE " == " 0" ]] || [[ " $MODE " == " pg" ] ]; then
18711871 debug_log " after pg test reached, MODE=$MODE "
18721872 # PG
18731873 FIC=" disabled"
@@ -1911,7 +1911,7 @@ if [ "$MODE" == "0" ] || [ "$MODE" == "pg" ]; then
19111911 debug_log " no pg pass"
19121912 else
19131913 # Attempt to verify Postgres connectivity (if psql is available)
1914- echo " --- Attempting Postgres connectivity check ---"
1914+ echo_log " --- Attempting Postgres connectivity check ---"
19151915 if test -x ${SPLUNK_HOME} /bin/psql 2> /dev/null; then
19161916 debug_log " psql binary found at ${SPLUNK_HOME} /bin/psql"
19171917 debug_log " Using pgpass file: ${PGPASS_FILE} "
@@ -1930,7 +1930,7 @@ if [ "$MODE" == "0" ] || [ "$MODE" == "pg" ]; then
19301930 echo_log " "
19311931 echo_log " ✅ Postgres connectivity verified ---"
19321932 # Check lsof is available before attempting to use it
1933- echo_log " TEST1
1933+ echo_log " TEST1"
19341934 if ! command -v lsof & > /dev/null; then
19351935 echo_log " ERROR: 'lsof' is not installed or not in PATH"
19361936 fi
@@ -2081,12 +2081,12 @@ fi
20812081 if [ ${BACKUPTYPE} -eq 2 ]; then
20822082 # full etc mode
20832083 if [ ${REMOTETYPE} -eq 2 ]; then
2084- FICETC=" ${REMOTEBACKUPDIR} /backupconfsplunk$- {extmode}etc-full-${INSTANCE} .tar.${EXTENSION} " ;
2084+ FICETC=" ${REMOTEBACKUPDIR} /backupconfsplunk- $ {extmode} etc-full-${INSTANCE} .tar.${EXTENSION} " ;
20852085 FICSCRIPT=" ${REMOTEBACKUPDIR} /backupconfsplunk-${extmode} scripts-${INSTANCE} .tar.${EXTENSION} " ;
20862086 FICKVSTORE=" ${REMOTEBACKUPDIR} /backupconfsplunk-${extmode} kvstore-${INSTANCE} .tar.${EXTENSION} " ;
20872087 FICKVDUMP=" ${REMOTEBACKUPDIR} /backupconfsplunk-kvdump-${INSTANCE} .tar.${EXTENSIONKV} " ;
20882088 FICSTATE=" ${REMOTEBACKUPDIR} /backupconfsplunk-${extmode} state-${INSTANCE} .tar.${EXTENSION} " ;
2089- SFICETC=" ${REMOTEOBJECTSTOREPREFIX} /backupconfsplunk$- {extmode}etc-full-${INSTANCE} .tar.${EXTENSION} " ;
2089+ SFICETC=" ${REMOTEOBJECTSTOREPREFIX} /backupconfsplunk- $ {extmode} etc-full-${INSTANCE} .tar.${EXTENSION} " ;
20902090 SFICSCRIPT=" ${REMOTEOBJECTSTOREPREFIX} /backupconfsplunk-${extmode} scripts-${INSTANCE} .tar.${EXTENSION} " ;
20912091 SFICKVSTORE=" ${REMOTEOBJECTSTOREPREFIX} /backupconfsplunk-${extmode} kvstore-${INSTANCE} .tar.${EXTENSION} " ;
20922092 SFICKVDUMP=" ${REMOTEOBJECTSTOREPREFIX} /backupconfsplunk-kvdump-${INSTANCE} .tar.${EXTENSIONKV} " ;
21662166 OPTION=" " ;
21672167 elif [ ${REMOTETECHNO} -eq 2 ]; then
21682168 # azure, see https://docs.microsoft.com/en-us/cli/azure/storage?view=azure-cli-latest#az-storage-copy
2169- if [[ " cloud_type" -eq 2 ]]; then
2169+ if [[ " $ cloud_type" -eq 2 ]]; then
21702170 # gcp
21712171 CPCMD=" gsutil -q cp" ;
21722172 OPTION=" " ;
23122312
23132313if [ " $INIT " == " 1" ]; then
23142314 echo_log " INIT mode , removing lock file so other backup process may run"
2315- ` rm ${SPLUNK_HOME} /var/run/splunkconf-init.lock`
2315+ rm ${SPLUNK_HOME} /var/run/splunkconf-init.lock
23162316fi
23172317
23182318debug_log " MODE=$MODE , end of splunkconf_backup script"
0 commit comments