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

Archive sooner - #17

Open
justizin wants to merge 4 commits into
aptible:masterfrom
VirtaHealth:archive_sooner
Open

Archive sooner#17
justizin wants to merge 4 commits into
aptible:masterfrom
VirtaHealth:archive_sooner

Conversation

@justizin

Copy link
Copy Markdown

Still testing this, but one of the concerns I had with the default behavior was waiting to archive the data until it was time to delete. If the data is already segmented by day, anything older than a day should always be archived.

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

echo "Deleting ${INDEX_NAME} from Elasticsearch."
curl -w "\n" -sS -XDELETE ${INDEX_URL}
echo curl -w "\n" -sS -XDELETE ${INDEX_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.

Is this change intentional? (and what is trying to achieve?)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

nope, this is ... probably why nothing is happening lol. i left debug echoes.

Comment thread src/backup-all-indexes.sh Outdated
{
: ${1:?"Error: expected index name passed as parameter"}
local INDEX_NAME=$1
local SNAPSHOT_URL=${REPOSITORY_URL}/${INDEX_NAME}

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.

You can probably skip SNAPSHOT_URL: it never gets called in this function.

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

CUTOFF_DATE=$(date --date="${MAX_DAYS_TO_KEEP} days ago" +"%Y.%m.%d")
echo "$(now) Archiving all indexes with logs before ${CUTOFF_DATE}."
ARCHIVE_CUTOFF_DATE=$(date --date="1 days ago" +"%Y.%m.%d") # why would we wait weeks to archive?

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.

I get where you're coming from but you can probably skip that comment here :)

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.

More importantly: I'm a little concerned about using exactly "1 day" as the cutoff. Using exactly one day sort of assumes that everybody agrees on what the date is — i.e. that they use the same timezone and their time is in sync —, which may not always be 100% accurate.

Unfortunately, as I noted in this other PR, snapshotting too early in this script means you may not end up snapshotting everything...

I figure we could either create a final snapshot before deleting an index, or give it 2 days before snapshotting..?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yeah, 2 days is good, but I'm unclear how the container running this script and the container the ES data is in would disagree.

My main concern is having ES die, and losing 7, 14, 30, whatever days of data because the archive waits until delete.

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.

Yeah, 2 days is good, but I'm unclear how the container running this script and the container the ES data is in would disagree.

If you're assuming this is running on Enclave, then yes, this is unlikely to happen since we're running Logstash using UTC as the timezone, and you're using this container which also uses UTC as the timezone.

However, that might not be the case for everyone using this: if someone runs Logstash in UTC, but executes this script from a different TZ, they might end up backing up their logs too early because the script thinks today is day N+1 (and thus backs up the logstash-N index), but Logstash thinks today is day N and continues to write to the logstash-N index, thus resulting in any logs written after the backup script runs to never be archived.

My main concern is having ES die, and losing 7, 14, 30, whatever days of data because the archive waits until delete.

Worth mentioning that, if you're assuming this is running on Enclave, this is largely moot considering the ES disk is actually backed up on a daily basis, though I can understand that you wanting to have your own archives.

Comment thread src/backup-all-indexes.sh Outdated
else
echo "$(now): ${index_name} archival failed."
fi
if [[ "${index_name:9}" > "${DELETE_CUTOFF_DATA}" ]]; then

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.

I'm fairly certain this should be DELETE_CUTOFF_DATE, not DELETE_CUTOFF_DATA (or this will delete all indices that are archive-able).

TBH, it's a real problem that this script does not run with set -o nounset, but for now, that's what it is :/

@rogthefrog

Copy link
Copy Markdown

FWIW I find the inconsistent nomenclature (snapshot, archive, backup) hard to follow.

Comment thread src/backup-all-indexes.sh Outdated
else
echo "$(now): ${index_name} archival failed."
fi
if [[ "${index_name:9}" > "${DELETE_CUTOFF_DATA}" ]]; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should the deletion be performed in all cases, even if the archival failed?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fine point!

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