Skip to content

Instantly share code, notes, and snippets.

@coderberry
Created September 23, 2015 18:59
Show Gist options
  • Save coderberry/e61a9112ed6b9ef30c41 to your computer and use it in GitHub Desktop.
Save coderberry/e61a9112ed6b9ef30c41 to your computer and use it in GitHub Desktop.
Open the last database backup file in a browser to download
#!/usr/bin/env ruby
require 'typhoeus'
require 'json'
TOKEN = File.read("/path/to/.cloud66/token")
STACK_ID = 'MY_UNIQUE_STACK_ID_ON_CLOUD66'
# Get backups
request = Typhoeus::Request.new("https://app.cloud66.com/api/3/stacks/#{STACK_ID}/backups.json", method: :get, headers: { Authorization: "Bearer #{TOKEN}" })
request.run
response = request.response
resp = JSON.parse(response.body)
backup_id = resp['response'][0]['id']
# Get backup files
request = Typhoeus::Request.new("https://app.cloud66.com/api/3/stacks/#{STACK_ID}/backups/#{backup_id}/files.json", method: :get, headers: { Authorization: "Bearer #{TOKEN}" })
request.run
response = request.response
resp = JSON.parse(response.body)
file_id = resp['response'][0]['id']
file_name = resp['response'][0]['name']
# Get backup file url
request = Typhoeus::Request.new("https://app.cloud66.com/api/3/stacks/#{STACK_ID}/backups/#{backup_id}/files/#{file_id}.json", method: :get, headers: { Authorization: "Bearer #{TOKEN}" })
request.run
response = request.response
resp = JSON.parse(response.body)
public_url = resp['response']['public_url'].gsub('%253D', '%3D')
system("open #{public_url}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment