Skip to content

Commit

Permalink
refactor: use sdk in backup
Browse files Browse the repository at this point in the history
  • Loading branch information
ryota-sakamoto committed May 15, 2023
1 parent ba9dc3a commit 65f7ec9
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions src/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,27 +517,25 @@ pub async fn backup(cx: app::Context, all_tables: bool) {
if all_tables {
println!("NOTE: --all-tables option is ignored without --list option. Just trying to create a backup for the target table...")
};
debug!(
"Taking a backof of the table '{}'",
cx.effective_table_name()
);

let table_name = cx.effective_table_name();
debug!("Taking a backof of the table '{}'", table_name);

let epoch: u64 = time::SystemTime::now()
.duration_since(time::SystemTime::UNIX_EPOCH)
.expect("should be able to generate UNIX EPOCH")
.as_secs();

let ddb = DynamoDbClient::new(cx.effective_region());

// You need to pass "table_name" and "backup_name". There's no other fields.
// https://rusoto.github.io/rusoto/rusoto_dynamodb/struct.CreateBackupInput.html
let req: CreateBackupInput = CreateBackupInput {
table_name: cx.effective_table_name(),
backup_name: format!("{}--dynein-{}", cx.effective_table_name(), epoch),
};
let config = cx.effective_sdk_config().await;
let ddb = DynamoDbSdkClient::new(&config);

debug!("this is the req: {:?}", req);
let req = ddb
.create_backup()
.table_name(&table_name)
.backup_name(format!("{}--dynein-{}", table_name, epoch));
debug!("backup req: {:?}", req);

match ddb.create_backup(req).await {
match req.send().await {
Err(e) => {
debug!("CreateBackup API call got an error -- {:#?}", e);
app::bye(1, &e.to_string());
Expand All @@ -548,9 +546,16 @@ pub async fn backup(cx: app::Context, all_tables: bool) {
println!("Backup creation has been started:");
println!(
" Backup Name: {} (status: {})",
details.backup_name, details.backup_status
details.backup_name.expect("should have backup name"),
details
.backup_status
.expect("should have backup status")
.as_str()
);
println!(
" Backup ARN: {}",
details.backup_arn.expect("should have backup arn")
);
println!(" Backup ARN: {}", details.backup_arn);
println!(
" Backup Size: {} bytes",
details.backup_size_bytes.expect("should have table size")
Expand Down

0 comments on commit 65f7ec9

Please sign in to comment.