This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
manuals:vps:api [2016/12/11 14:44] – created toms | manuals:vps:api [2017/03/27 07:37] – API v4.1 Aither | ||
---|---|---|---|
Line 10: | Line 10: | ||
===== API Documentation ===== | ===== API Documentation ===== | ||
The API documentation, | The API documentation, | ||
- | parameters can be found at https:// | + | parameters can be found at https:// |
Even without logging in, you can see a list of all objects, i.e. even those that only | Even without logging in, you can see a list of all objects, i.e. even those that only | ||
Line 536: | Line 536: | ||
< | < | ||
Although these examples are still valid, the CLI client already contains | Although these examples are still valid, the CLI client already contains | ||
- | [[navody:vps:datasety#stahovani_zaloh|commands]] which make downloading backups | + | [[manuals:vps:datasets#downloading_backups|commands]] which make downloading backups |
even easier. | even easier. | ||
</ | </ | ||
Line 546: | Line 546: | ||
require ' | require ' | ||
- | api = VpsFree::Client:: | + | api = VpsFree:: |
api.authenticate(: | api.authenticate(: | ||
- | |||
- | downloads = [] | ||
api.dataset.list(role: | api.dataset.list(role: | ||
last_snapshot = ds.snapshot.list.last | last_snapshot = ds.snapshot.list.last | ||
+ | # This action may take up to several hours | ||
dl = api.snapshot_download.create(snapshot: | dl = api.snapshot_download.create(snapshot: | ||
- | | + | |
unless dl.api_response.ok? | unless dl.api_response.ok? | ||
warn "# | warn "# | ||
next | next | ||
end | end | ||
+ | | ||
+ | # The file is ready for download | ||
+ | puts " | ||
+ | `wget #{dl.url}` | ||
- | | + | # Finally, delete |
- | end | + | dl.delete |
- | + | ||
- | # vpsAdmin is now creating a tar.gz with the backup and it will take a while until it can be | + | |
- | # downloaded. There are regular checks for the “ready” parameter for all archives. | + | |
- | puts " | + | |
- | loop do | + | |
- | sleep(5*60) | + | |
- | + | ||
- | downloads.delete_if do |id| | + | |
- | dl = api.snapshot_download.find(id) | + | |
- | + | ||
- | unless dl.api_response.ok? | + | |
- | warn " | + | |
- | next(true) | + | |
- | end | + | |
- | | + | |
- | if dl.ready | + | |
- | puts " | + | |
- | `wget "# | + | |
- | | + | |
- | true | + | |
- | + | ||
- | else | + | |
- | false | + | |
- | end | + | |
- | end | + | |
- | + | ||
- | break if downloads.empty? | + | |
end | end | ||
Line 601: | Line 577: | ||
require ' | require ' | ||
- | api = VpsFree::Client:: | + | api = VpsFree:: |
api.authenticate(: | api.authenticate(: | ||
Line 607: | Line 583: | ||
# Creating a new snapshot | # Creating a new snapshot | ||
ds.snapshot.create | ds.snapshot.create | ||
- | |||
- | # Naive waiting until the snapshot is created. A different option would be checking | ||
- | # the state of the corresponding transaction chain. | ||
- | sleep(10) | ||
# Deleting older snapshots | # Deleting older snapshots | ||
Line 626: | Line 598: | ||
snap.delete | snap.delete | ||
deleted += 1 | deleted += 1 | ||
- | |||
- | # Once again, naive waiting until the action finishes. | ||
- | sleep(30) | ||
end | end | ||
end | end |