Class: SFRest::Backup

Inherits:
Object
  • Object
show all
Defined in:
lib/sfrest/backup.rb

Overview

Backup a site or restore onto that site

Instance Method Summary collapse

Constructor Details

#initialize(conn) ⇒ Backup

Returns a new instance of Backup.

Parameters:



7
8
9
# File 'lib/sfrest/backup.rb', line 7

def initialize(conn)
  @conn = conn
end

Instance Method Details

#backup_url(site_id, backup_id, lifetime = 60) ⇒ Object

Gets a url to download a backup

Parameters:

  • site_id (Integer)

    Node id of site

  • backup_id (Integer)

    Id of backup to delete

  • lifetime (Integer) (defaults to: 60)

    TTL of the url



44
45
46
# File 'lib/sfrest/backup.rb', line 44

def backup_url(site_id, backup_id, lifetime = 60)
  @conn.get("/api/v1/sites/#{site_id}/backups/#{backup_id}/url?lifetime=#{lifetime}")
end

#create_backup(site_id, datum = nil) ⇒ Object

Backs up a site.

Parameters:

  • site_id (Integer)
  • datum (Hash) (defaults to: nil)

    Options to the backup

Options Hash (datum):

  • 'label' (String)
  • 'callback_url' (Url)
  • 'callback_method' (String)

    GET|POST

  • 'caller_data' (Json)

    json encoded string



35
36
37
38
# File 'lib/sfrest/backup.rb', line 35

def create_backup(site_id, datum = nil)
  current_path = "/api/v1/sites/#{site_id}/backup"
  @conn.post(current_path, datum.to_json)
end

#delete_backup(site_id, backup_id) ⇒ Object

Deletes a site backup.

Parameters:

  • site_id (Integer)

    Node id of site

  • backup_id (Integer)

    Id of backup to delete



23
24
25
26
# File 'lib/sfrest/backup.rb', line 23

def delete_backup(site_id, backup_id)
  current_path = "/api/v1/sites/#{site_id}/backups/#{backup_id}"
  @conn.delete(current_path)
end

#expiration_getHash

Gets the current the backup expiration and automatic deletion setting.

Returns:

  • (Hash)


59
60
61
# File 'lib/sfrest/backup.rb', line 59

def expiration_get
  @conn.get('/api/v1/backup-expiration/')
end

#expiration_set(days) ⇒ Object

Configures the backup expiration and automatic deletion setting.

Parameters:

  • days (Integer)

    Number of days after which backups are deleted.



50
51
52
53
54
55
# File 'lib/sfrest/backup.rb', line 50

def expiration_set(days)
  payload = {
    'expiration_days' => days
  }
  @conn.put('/api/v1/backup-expiration/', payload.to_json)
end

#get_backups(site_id, datum = nil) ⇒ Hash

cool stuff goes here

Parameters:

  • site_id (Integer)

    the node id of the site node

Returns:

  • (Hash)


14
15
16
17
18
# File 'lib/sfrest/backup.rb', line 14

def get_backups(site_id, datum = nil)
  current_path = "/api/v1/sites/#{site_id}/backups"
  pb = SFRest::Pathbuilder.new
  @conn.get URI.parse(pb.build_url_query(current_path, datum)).to_s
end