Skip to content

Commit

Permalink
Add backup capture
Browse files Browse the repository at this point in the history
  • Loading branch information
will committed May 19, 2022
1 parent cafe185 commit cafe0a1
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- `cb backup list` shows current backups for a cluster.
- `cb suspend` and `resume` to temporarily stop running a cluster.
- `cb backup capture` manually starts a backup for a cluster.

## [2.0.0] - 2022-05-17
### Added
Expand Down
12 changes: 12 additions & 0 deletions spec/cb/backup_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,22 @@ private class BackupTestClient < CB::Client
end
end

private def make_ba
CB::BackupCapture.new(BackupTestClient.new(TEST_TOKEN))
end

private def make_bl
CB::BackupList.new(BackupTestClient.new(TEST_TOKEN))
end

describe CB::BackupCapture do
it "validates that cluster_id is correct" do
ba = make_ba
ba.cluster_id = "afpvoqooxzdrriu6w3bhqo55c4"
expect_cb_error(/cluster id/) { ba.cluster_id = "notaneid" }
end
end

describe CB::BackupList do
it "validates that cluster_id is correct" do
bl = make_bl
Expand Down
6 changes: 6 additions & 0 deletions spec/cb/completion_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,17 @@ describe CB::Completion do
it "completes backup" do
result = parse("cb backup ")
result.should have_option "list"
result.should have_option "capture"

result = parse("cb backup list ")
result.should eq ["abc\tmy team/my cluster"]
result = parse("cb backup list abc ")
result.should_not have_option "abc"

result = parse("cb backup capture ")
result.should eq ["abc\tmy team/my cluster"]
result = parse("cb backup capture abc ")
result.should_not have_option "abc"
end

it "completes detach" do
Expand Down
14 changes: 14 additions & 0 deletions src/cb/backup.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
require "./action"

module CB
class BackupCapture < Action
eid_setter cluster_id

def run
check_required_args do |missing|
missing << "cluster id" unless cluster_id
end

client.put "clusters/#{cluster_id}/actions/start-backup"
c = client.get_cluster cluster_id
output << "requested backup capture of " << c.name.colorize.t_name << "\n"
end
end

class Client
jrecord Backup,
name : String,
Expand Down
3 changes: 2 additions & 1 deletion src/cb/completion.cr
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,9 @@ class CB::Completion
when ""
return [
"list\tlist backups",
"capture\tstart a new backup",
]
when "list"
when "list", "capture"
return cluster_suggestions if @args.size == 3
end

Expand Down
8 changes: 7 additions & 1 deletion src/cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,19 @@ op = OptionParser.new do |parser|
# Backup Management
#
parser.on("backup", "Manage backups") do
parser.banner = "cb backup <list>"
parser.banner = "cb backup <list|capture>"

parser.on("list", "List backups for a cluster") do
list = set_action BackupList
parser.banner = "cb backup list <cluster id>"
parser.unknown_args { |args| list.cluster_id = get_id_arg.call(args) }
end

parser.on("capture", "Start capturing a new backup for a cluster") do
capture = set_action BackupCapture
parser.banner = "cb backup capture <cluster id>"
parser.unknown_args { |args| capture.cluster_id = get_id_arg.call(args) }
end
end

parser.on("suspend", "Temporarily turn off a cluster") do
Expand Down

0 comments on commit cafe0a1

Please sign in to comment.