Created
February 3, 2016 01:03
-
-
Save itolosa/a1d4e43ce2386d1628f0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'droplet_kit' | |
token = 'put-your-token-id' | |
client = DropletKit::Client.new(access_token: token) | |
if File.exist?('/root/droplet_id') | |
begin | |
droplet_id = File.read('/root/droplet_id') | |
res = client.droplets.delete(id: droplet_id) | |
until res.status == "completed" | |
res = client.actions.find(id: res.id) | |
sleep(2) | |
end | |
rescue | |
#pass | |
ensure | |
File.delete('/root/droplet_id') | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# backup - backup service job file | |
description "backup daemon" | |
# When to start the service | |
start on runlevel [2345] | |
# When to stop the service | |
stop on runlevel [016] | |
# Automatically restart process if crashed | |
respawn | |
# Specify working directory | |
chdir /root | |
exec ruby backup.rb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'droplet_kit' | |
droplet_id = 9771628 | |
token = 'put-your-token-id' | |
client = DropletKit::Client.new(access_token: token) | |
droplet = client.droplets.find(id: droplet_id) | |
sleep(10) | |
begin | |
res = client.droplet_actions.shutdown(droplet_id: droplet.id) | |
until res.status == "completed" | |
res = client.actions.find(id: res.id) | |
sleep(2) | |
end | |
rescue | |
#do nothing | |
end | |
res = client.droplet_actions.snapshot(droplet_id: droplet.id, name: "#{droplet.name} (#{droplet.id}) #{Time.now.strftime("%H:%M:%S %d-%m-%Y")}") | |
until res.status == "completed" | |
res = client.actions.find(id: res.id) | |
sleep(2) | |
end | |
res = client.droplet_actions.power_on(droplet_id: droplet.id) | |
until res.status == "completed" | |
res = client.actions.find(id: res.id) | |
sleep(2) | |
end | |
loop | |
sleep(1000) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'droplet_kit' | |
token = 'put-your-token-id' | |
client = DropletKit::Client.new(access_token: token) | |
droplet = DropletKit::Droplet.new(name: 'bot', region: 'sfo1', image: 'backup-helper', size: '512mb') | |
#save droplet id | |
begin | |
created = client.droplets.create(droplet) | |
File.write('/root/droplet_id', created.id) | |
until created.status == "active" | |
created = client.droplets.find(id: created.id) | |
sleep(2) | |
end | |
rescue | |
File.delete('/root/droplet_id') | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
start on startup | |
task | |
exec ruby after-backup.rb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment