Class: SFRest::Backup
- Inherits:
-
Object
- Object
- SFRest::Backup
- Defined in:
- lib/sfrest/backup.rb
Overview
Backup a site or restore onto that site
Instance Method Summary collapse
-
#backup_url(site_id, backup_id, lifetime = 60) ⇒ Object
Gets a url to download a backup.
-
#create_backup(site_id, datum = nil) ⇒ Object
Backs up a site.
-
#delete_backup(site_id, backup_id) ⇒ Object
Deletes a site backup.
- #execute_backup(options = {}) ⇒ Object
- #execute_drush_backup(acsf, site_nid, name, components, user) ⇒ Object
- #execute_rest_backup(rconn, site_nid, name, components) ⇒ Object
-
#expiration_get ⇒ Hash
Gets the current the backup expiration and automatic deletion setting.
-
#expiration_set(days) ⇒ Object
Configures the backup expiration and automatic deletion setting.
-
#get_backups(site_id, datum = nil) ⇒ Hash
cool stuff goes here.
-
#initialize(conn) ⇒ Backup
constructor
A new instance of Backup.
- #parse_components(components_json) ⇒ Object
- #parse_response(response) ⇒ Object
Constructor Details
#initialize(conn) ⇒ Backup
Returns a new instance of Backup.
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
91 92 93 |
# File 'lib/sfrest/backup.rb', line 91 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.
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.
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 |
#execute_backup(options = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/sfrest/backup.rb', line 40 def execute_backup( = {}) api = [:api] rconn = [:rconn] acsf = [:acsf] site_nid = [:site_nid] name = [:name] components = [:components] user = [:user] case api when 'rest' execute_rest_backup(rconn, site_nid, name, components) when 'drush' execute_drush_backup(acsf, site_nid, name, components, user) else raise "Unsupported API: #{api}" end end |
#execute_drush_backup(acsf, site_nid, name, components, user) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/sfrest/backup.rb', line 67 def execute_drush_backup(acsf, site_nid, name, components, user) drush_components = components.is_a?(Array) ? components.join(',') : components drush_cmd = "sf-backup #{site_nid} \"#{name}\" --components=\"#{drush_components}\" --user=#{user} --format=json" drush_cmd_update = acsf.drush drush_cmd result = acsf.factory_ssh.exec!(drush_cmd_update).strip JSON.parse(result) end |
#execute_rest_backup(rconn, site_nid, name, components) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/sfrest/backup.rb', line 59 def execute_rest_backup(rconn, site_nid, name, components) payload = { 'label' => name, 'components' => components }.to_json rconn.post "/api/v1/sites/#{site_nid}/backup", payload end |
#expiration_get ⇒ Hash
Gets the current the backup expiration and automatic deletion setting.
106 107 108 |
# File 'lib/sfrest/backup.rb', line 106 def expiration_get @conn.get('/api/v1/backup-expiration/') end |
#expiration_set(days) ⇒ Object
Configures the backup expiration and automatic deletion setting.
97 98 99 100 101 102 |
# File 'lib/sfrest/backup.rb', line 97 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
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 |
#parse_components(components_json) ⇒ Object
81 82 83 84 85 |
# File 'lib/sfrest/backup.rb', line 81 def parse_components(components_json) JSON.parse(components_json) rescue JSON::ParserError components_json # Keep the original string if it's not valid JSON end |
#parse_response(response) ⇒ Object
75 76 77 78 79 |
# File 'lib/sfrest/backup.rb', line 75 def parse_response(response) raise "Unexpected response type: #{response.class}" unless response.is_a?(Hash) [response['task_id'], response['message']] end |