com.cloudbees.sdk.commands.db.DatabaseBackupList Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2010-2013, CloudBees Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.cloudbees.sdk.commands.db;
import com.cloudbees.api.*;
import com.cloudbees.sdk.cli.BeesCommand;
import com.cloudbees.sdk.cli.CLICommand;
import com.cloudbees.sdk.utils.Helper;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* @author Fabian Donze
*/
@BeesCommand(group="Database", description = "List database backups")
@CLICommand("db:backup:list")
public class DatabaseBackupList extends DatabaseBase {
public DatabaseBackupList() {
}
@Override
protected boolean execute() throws Exception {
String dbId = getDatabaseName();
BeesClient client = getBeesClient(BeesClient.class, dbId);
DatabaseBackupListResponse res = client.databaseBackupList(dbId);
if (isTextOutput()) {
for (DatabaseBackupInfo backupInfo: res.getBackups()) {
System.out.println( "Backup ID : " + backupInfo.getId());
System.out.println( "Created : " + DateHelper.toW3CDateString(backupInfo.getCreated()));
Map settings = backupInfo.getSettings();
if (settings != null) {
List list = new ArrayList(settings.size());
for (Map.Entry entry: settings.entrySet()) {
list.add(s(entry.getKey(), 16) + ": " + entry.getValue());
}
Collections.sort(list);
for (String item : list)
System.out.println(item);
}
System.out.println();
}
} else
printOutput(res, DatabaseBackupListResponse.class, DatabaseBackupInfo.class);
return true;
}
private String s(String str, int length) {
return Helper.getPaddedString(str, length);
}
}