Module: Elasticsearch::API::Snapshot::Actions

Included in:
SnapshotClient
Defined in:
lib/elasticsearch/api/namespace/snapshot.rb,
lib/elasticsearch/api/actions/snapshot/get.rb,
lib/elasticsearch/api/actions/snapshot/create.rb,
lib/elasticsearch/api/actions/snapshot/delete.rb,
lib/elasticsearch/api/actions/snapshot/restore.rb,
lib/elasticsearch/api/actions/snapshot/get_repository.rb,
lib/elasticsearch/api/actions/snapshot/create_repository.rb,
lib/elasticsearch/api/actions/snapshot/delete_repository.rb

Instance Method Summary collapse

Instance Method Details

#create(arguments = {}) ⇒ Object

Create a new snapshot in the repository

Examples:

Create a snapshot of the whole cluster in the ‘my-backups` repository


client.snapshot.create repository: 'my-backups', snapshot: 'snapshot-1'

Create a snapshot for specific indices in the ‘my-backups` repository


client.snapshot.create repository: 'my-backups',
                       snapshot: 'snapshot-2',
                       body: { indices: 'foo,bar', ignore_unavailable: true }

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :repository (String)

    A repository name (Required)

  • :snapshot (String)

    A snapshot name (Required)

  • :body (Hash)

    The snapshot definition

  • :master_timeout (Time)

    Explicit operation timeout for connection to master node

  • :wait_for_completion (Boolean)

    Whether the request should block and wait until the operation has completed

Raises:

  • (ArgumentError)

See Also:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/elasticsearch/api/actions/snapshot/create.rb', line 27

def create(arguments={})
  raise ArgumentError, "Required argument 'repository' missing" unless arguments[:repository]
  raise ArgumentError, "Required argument 'snapshot' missing"   unless arguments[:snapshot]
  valid_params = [
    :master_timeout,
    :wait_for_completion ]

  repository = arguments.delete(:repository)
  snapshot   = arguments.delete(:snapshot)

  method = 'PUT'
  path   = Utils.__pathify( '_snapshot', Utils.__escape(repository), Utils.__escape(snapshot) )

  params = Utils.__validate_and_extract_params arguments, valid_params
  body   = arguments[:body]

  perform_request(method, path, params, body).body
end

#create_repository(arguments = {}) ⇒ Object

Create a repository for storing snapshots

Examples:

Create a repository at ‘/tmp/backup`


client.snapshot.create_repository repository: 'my-backups',
                                  body: {
                                    type: 'fs',
                                    settings: { location: '/tmp/backup', compress: true  }
                                  }

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :repository (String)

    A repository name (Required)

  • :body (Hash)

    The repository definition (Required)

  • :master_timeout (Time)

    Explicit operation timeout for connection to master node

  • :timeout (Time)

    Explicit operation timeout

Raises:

  • (ArgumentError)

See Also:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/elasticsearch/api/actions/snapshot/create_repository.rb', line 23

def create_repository(arguments={})
  raise ArgumentError, "Required argument 'repository' missing" unless arguments[:repository]
  raise ArgumentError, "Required argument 'body' missing"       unless arguments[:body]
  valid_params = [
    :repository,
    :master_timeout,
    :timeout ]

  repository = arguments.delete(:repository)

  method = 'PUT'
  path   = Utils.__pathify( '_snapshot', Utils.__escape(repository) )

  params = Utils.__validate_and_extract_params arguments, valid_params
  body   = arguments[:body]

  perform_request(method, path, params, body).body
end

#delete(arguments = {}) ⇒ Object

Note:

Will also abort a currently running snapshot.

Delete a snapshot from the repository

Examples:

Delete the ‘snapshot-1` snapshot


client.snapshot.delete repository: 'my-backups', snapshot: 'snapshot-1'

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :repository (String)

    A repository name (Required)

  • :snapshot (String)

    A snapshot name (Required)

  • :master_timeout (Time)

    Explicit operation timeout for connection to master node

Raises:

  • (ArgumentError)

See Also:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/elasticsearch/api/actions/snapshot/delete.rb', line 20

def delete(arguments={})
  raise ArgumentError, "Required argument 'repository' missing" unless arguments[:repository]
  raise ArgumentError, "Required argument 'snapshot' missing"   unless arguments[:snapshot]

  valid_params = [
    :master_timeout ]

  repository = arguments.delete(:repository)
  snapshot   = arguments.delete(:snapshot)

  method = 'DELETE'
  path   = Utils.__pathify( '_snapshot', Utils.__escape(repository), Utils.__listify(snapshot) )

  params = Utils.__validate_and_extract_params arguments, valid_params
  body   = nil

  perform_request(method, path, params, body).body
end

#delete_repository(arguments = {}) ⇒ Object

Delete a specific repository or repositories

Examples:

Delete the ‘my-backups` repository


client.snapshot.delete_repository repository: 'my-backups'

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :repository (List)

    A comma-separated list of repository names (Required)

  • :master_timeout (Time)

    Explicit operation timeout for connection to master node

  • :timeout (Time)

    Explicit operation timeout

Raises:

  • (ArgumentError)

See Also:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/elasticsearch/api/actions/snapshot/delete_repository.rb', line 18

def delete_repository(arguments={})
  raise ArgumentError, "Required argument 'repository' missing" unless arguments[:repository]

  valid_params = [
    :master_timeout,
    :timeout ]

  repository = arguments.delete(:repository)

  method = 'DELETE'
  path   = Utils.__pathify( '_snapshot', Utils.__listify(repository) )

  params = Utils.__validate_and_extract_params arguments, valid_params
  body   = nil

  perform_request(method, path, params, body).body
end

#get(arguments = {}) ⇒ Object

Return information about specific (or all) snapshots

Examples:

Return information about the ‘snapshot-2` snapshot


client.snapshot.get repository: 'my-backup', snapshot: 'snapshot-2'

Return information about multiple snapshots


client.snapshot.get repository: 'my-backup', snapshot: ['snapshot-2', 'snapshot-3']

Return information about all snapshots in the repository


client.snapshot.get repository: 'my-backup', snapshot: '_all'

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :repository (String)

    A repository name (Required)

  • :snapshot (List)

    A comma-separated list of snapshot names (Required)

  • :master_timeout (Time)

    Explicit operation timeout for connection to master node

Raises:

  • (ArgumentError)

See Also:



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/elasticsearch/api/actions/snapshot/get.rb', line 26

def get(arguments={})
  raise ArgumentError, "Required argument 'repository' missing" unless arguments[:repository]
  raise ArgumentError, "Required argument 'snapshot' missing"   unless arguments[:snapshot]

  valid_params = [
    :master_timeout ]

  repository = arguments.delete(:repository)
  snapshot   = arguments.delete(:snapshot)

  method = 'GET'
  path   = Utils.__pathify( '_snapshot', Utils.__escape(repository), Utils.__listify(snapshot) )

  params = Utils.__validate_and_extract_params arguments, valid_params
  body   = nil

  perform_request(method, path, params, body).body
end

#get_repository(arguments = {}) ⇒ Object

Get information about snapshot repositories or a specific repository

Examples:

Get all repositories


client.snapshot.get_repository

Get a specific repository


client.snapshot.get_repository repository: 'my-backups'

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :repository (List)

    A comma-separated list of repository names. Leave blank or use ‘_all` to get a list of repositories

  • :master_timeout (Time)

    Explicit operation timeout for connection to master node

  • :local (Boolean)

    Return local information, do not retrieve the state from master node (default: false)

See Also:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/elasticsearch/api/actions/snapshot/get_repository.rb', line 24

def get_repository(arguments={})
  valid_params = [
    :master_timeout,
    :local ]

  repository = arguments.delete(:repository)

  method = 'GET'
  path   = Utils.__pathify( '_snapshot', Utils.__escape(repository) )

  params = Utils.__validate_and_extract_params arguments, valid_params
  body   = nil

  perform_request(method, path, params, body).body
end

#restore(arguments = {}) ⇒ Object

Note:

You cannot restore into an open index, you have to Indices::Actions#close it first

Restore the state from a snapshot

Examples:

Restore from the ‘snapshot-1` snapshot


client.snapshot.restore repository: 'my-backups', snapshot: 'snapshot-1'

Restore a specific index under a different name


client.snapshot.restore repository: 'my-backups',
                        snapshot: 'snapshot-5',
                        body: {
                          rename_pattern: "^(.*)$",
                          rename_replacement: "restored_$1"
                        }

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :repository (String)

    A repository name (Required)

  • :snapshot (String)

    A snapshot name (Required)

  • :body (Hash)

    Details of what to restore

  • :master_timeout (Time)

    Explicit operation timeout for connection to master node

  • :wait_for_completion (Boolean)

    Should this request wait until the operation has completed before returning

Raises:

  • (ArgumentError)

See Also:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/elasticsearch/api/actions/snapshot/restore.rb', line 31

def restore(arguments={})
  raise ArgumentError, "Required argument 'repository' missing" unless arguments[:repository]
  raise ArgumentError, "Required argument 'snapshot' missing"   unless arguments[:snapshot]

  valid_params = [
    :master_timeout,
    :wait_for_completion ]

  repository = arguments.delete(:repository)
  snapshot   = arguments.delete(:snapshot)

  method = 'POST'
  path   = Utils.__pathify( '_snapshot', Utils.__escape(repository), Utils.__escape(snapshot), '_restore' )

  params = Utils.__validate_and_extract_params arguments, valid_params
  body   = arguments[:body]

  perform_request(method, path, params, body).body
end