Skip to content
This repository was archived by the owner on Feb 18, 2026. It is now read-only.

added new features backup, slack notification, named indices - #16

Open
f41gh7 wants to merge 1 commit into
aptible:masterfrom
f41gh7:master
Open

added new features backup, slack notification, named indices#16
f41gh7 wants to merge 1 commit into
aptible:masterfrom
f41gh7:master

Conversation

@f41gh7

@f41gh7 f41gh7 commented Oct 10, 2017

Copy link
Copy Markdown

Backup: now indices before cutoff date are backuped to S3 without deletion.

Named indices: you can set array of indices - INDEX_ARRAY="logstash filebeat etc etc", backup script ll iterate it.

Slack notification: results of backup ll send to slack, if slack hook set.

@krallin krallin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your time. I'm not sure this is quite ready to be merged in.

If you're planning the changes I requested, let me know, and I can provide further guidance.

Thanks!

Comment thread src/backup-all-indexes.sh
REPOSITORY_NAME=${REPOSITORY_NAME:-logstash_snapshots}
WAIT_SECONDS=${WAIT_SECONDS:-1800}
MAX_DAYS_TO_KEEP=${MAX_DAYS_TO_KEEP:-30}
MAX_DAYS_TO_KEEP=${MAX_DAYS_TO_KEEP:-60}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you meant to commit this?

Comment thread src/backup-all-indexes.sh

curl --fail -w "\n" -sS -XPUT ${SNAPSHOT_URL} -d "{
\"indices\": \"${INDEX_NAME}\",
\"ignore_unavailable\": true,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this change?

Comment thread src/backup-all-indexes.sh
for index in $(curl -sS ${DATABASE_URL}/_cat/indices | grep $index_nm- | sed $SUBSTITUTION | sort); do

# debug information
echo "$index"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to commit this?

Comment thread README.md
* `S3_BUCKET_BASE_PATH`: Destination path within bucket (Optional)
* `S3_ACCESS_KEY_ID`: The access key you generated in step 3.
* `S3_SECRET_ACCESS_KEY`: The secret key you generated in step 3.
* `INDEX_ARRAY`: array of indices, INDEX_ARRAY="logstash nginx", separated with white space

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should explain how these indice names should be formatted. logstash indices have a format we can reasonably rely on to extract the date, but that's not the case with arbitrary indices.

Comment thread src/backup-all-indexes.sh
: ${S3_ACCESS_KEY_ID:?"Error: S3_ACCESS_KEY_ID environment variable not set"}
: ${S3_SECRET_ACCESS_KEY:?"Error: S3_SECRET_ACCESS_KEY environment variable not set"}
# list of index patterns to backup, should be separated with white space 'logstash filebeat'
INDEX_ARRAY=${INDEX_ARRAY:-logstash}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why put this one here when all other default variables are below?

Comment thread src/backup-all-indexes.sh
local SNAPSHOT_URL=${REPOSITORY_URL}/${INDEX_NAME}
local INDEX_URL=${DATABASE_URL}/${INDEX_NAME}

grep -q SUCCESS <(curl -sS ${SNAPSHOT_URL})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some major code duplication going on over here with archive_index - this would need to be fixed.

Comment thread src/backup-all-indexes.sh

# debug information
echo "$index"
CURR_DATE=`echo $index | sed -re $SUBSTITUTION_date`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use $() for consistency with everything else in this file?

Comment thread src/backup-all-indexes.sh
let fl++
fi
# if less then cuttoff date, just backup it to s3 without deletion
else

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the logic above just checks for "any snapshot exists" to mean "this is safe to delete" (because that's how this has worked so far). However, if you're now snapshotting indices regardless of their creation date, you might end up creating a snapshot for today, which will be incomplete.

Unfortunately, since that means a snapshot exists, it seems that no final snapshot will be created before finally deleting the index.

Am I missing something here?

Comment thread src/backup-all-indexes.sh
done

echo -e "results of archiving are -> index_name -> $B $index_nm $NB backuped -> $G $bk $N, archived -> $ar $R, failed -> $fl $N"
# formating array with message, that ll be send to slack

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is off here

Comment thread src/backup-all-indexes.sh
# if slack webhook set, send notify
if [[ -z "$SLACK_HOOK" ]]; then

echo "slack hook is not defined"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to remind users that they haven't enabled this feature every time the job runs. If $SLACK_HOOK is set, then notify, if not, then skip it altogether.

Comment thread src/backup-all-indexes.sh
fi
fi

# itterate array of indices

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo itterate --> iterate

Comment thread src/backup-all-indexes.sh
let ar++
else
echo "$(now): ${index} archival failed."
let fl++

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent is off by 1 space

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants