Awesome-Python-Scripts/elastic-snapshot
dependabot[bot] 45a953de72
Bump requests from 2.24.0 to 2.31.0 in /elastic-snapshot
Bumps [requests](https://github.com/psf/requests) from 2.24.0 to 2.31.0.
- [Release notes](https://github.com/psf/requests/releases)
- [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md)
- [Commits](https://github.com/psf/requests/compare/v2.24.0...v2.31.0)

---
updated-dependencies:
- dependency-name: requests
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-23 06:01:15 +00:00
..
elastic-snapshot.py added elastic-snapshot script (#193) 2020-10-21 09:05:58 +05:30
README.md added elastic-snapshot script (#193) 2020-10-21 09:05:58 +05:30
requirements.txt Bump requests from 2.24.0 to 2.31.0 in /elastic-snapshot 2023-05-23 06:01:15 +00:00

elastic-snapshot.py

This python3 script helps create snapshots in an elasticsearch cluster. Setting up elasticsearch and creating a snapshot repository are covered in the elasticsearch documentation If a snapshot is already in progress it will sleep for 5 minutes and try again.

  • requires the requests library to be installed
  • The default behavior is to get a list of snapshots for localhost and the backups snapshot repository
  • snapshots are created with at least a minimum of meta data: {taken_by: username, taken_because: 'Snapshot updated for: not specified}
  • This script assumes indices are named with dates in the form indexname-YYYY.MM.DD so it can use the period to select indices
  • --testing flag allows a comma separated list of indices to be supplied. In this case, the period will be used only for the snapshot name.
  • optional args and default values:
$   python3 elastic-snapshot.py [optional args]
    (-a|--action=list) snapshot action to perform (list, create, restore)
    (-h|--hostname=localhost:9200) 
    (-i test* |--index=test*) index name pattern to work on                
    (-l backups|--location=backups) snapshot repository name
    (-n|--noop) do not actually perform the API call but print it to stdout
    (-p|--period=2020.01) period for snapshot, unless --testing every index matching pattern indexname*-<period>* is implied
    (-r|--reason='not specified') snapshot reason for inclusion in metadata
    (-t|--testing=False) allows specifying multiple index names in --index
    (-v|--verbose=False) get verbose output to std out
  • examples:
$ python3 elastic-snapshot.py
# returns a list of the snapshots from localhost:9200

$ python3 elastic-snapshot.py --action create --index filebeat* --period 2020.08
# creates a snapshot named filebeat-2020.08-<timestamp> that includes all indices that match the pattern filebeat*-2020.08*

$ python3 elastic-snapshot.py -a create -i metricbeat* -p 2020.08 -l my_snapshots -v
# creates a snapshot named metricbeat-2020.08-<timestamp> in the snapshot repository named my_snapshots.  This snapshot will contain any index that matches the pattern metricbeat*-2020.08.  Verbose output will be printed to standard output