Search in sources :

Example 1 with DbBackupHistoryInfo

use of com.cubrid.cubridmanager.core.cubrid.database.model.DbBackupHistoryInfo in project cubrid-manager by CUBRID.

the class BackupDatabaseDialog method getBackupHistoryInfoList.

/**
	 *
	 * Get backup history information list
	 *
	 * @return the backup history information list
	 */
private List<Map<String, String>> getBackupHistoryInfoList() {
    List<Map<String, String>> list = new ArrayList<Map<String, String>>();
    if (dbBackupInfo != null) {
        List<DbBackupHistoryInfo> dbBackupHistoryInfoList = dbBackupInfo.getBackupHistoryList();
        if (dbBackupHistoryInfoList != null) {
            int size = dbBackupHistoryInfoList.size();
            for (int i = 0; i < size; i++) {
                DbBackupHistoryInfo historyInfo = dbBackupHistoryInfoList.get(i);
                Map<String, String> map = new HashMap<String, String>();
                map.put("0", historyInfo.getLevel());
                String dateStr = historyInfo.getDate();
                if (dateStr != null && dateStr.trim().length() > 0) {
                    String[] dateStrArr = dateStr.split("\\.");
                    if (dateStrArr.length == 5) {
                        dateStr = dateStrArr[0] + "." + dateStrArr[1] + "." + dateStrArr[2] + " " + dateStrArr[3] + ":" + dateStrArr[4];
                    }
                    map.put("1", dateStr);
                }
                String sizeStr = historyInfo.getSize();
                NumberFormat nf = NumberFormat.getInstance();
                nf.setMaximumFractionDigits(2);
                if (sizeStr != null && sizeStr.matches("^\\d+$")) {
                    map.put("2", nf.format(Integer.parseInt(sizeStr) / (1024 * 1024)));
                }
                String path = FileUtil.changeSeparatorByOS(historyInfo.getPath(), database.getServer().getServerInfo().getServerOsInfo());
                map.put("3", path);
                list.add(map);
            }
        }
    }
    return list;
}
Also used : DbBackupHistoryInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DbBackupHistoryInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) NumberFormat(java.text.NumberFormat)

Example 2 with DbBackupHistoryInfo

use of com.cubrid.cubridmanager.core.cubrid.database.model.DbBackupHistoryInfo in project cubrid-manager by CUBRID.

the class GetDbBackupInfoTask method getDbBackupInfo.

/**
	 * 
	 * Get database backup information
	 * 
	 * @return DbBackupInfo the instance of DbBackupInfo
	 */
public DbBackupInfo getDbBackupInfo() {
    TreeNode response = getResponse();
    if (response == null || (this.getErrorMsg() != null && getErrorMsg().trim().length() > 0)) {
        return null;
    }
    DbBackupInfo dbBackupInfo = new DbBackupInfo();
    String dbDir = response.getValue("dbdir");
    dbBackupInfo.setDbDir(dbDir);
    String freeSpace = response.getValue("freespace");
    dbBackupInfo.setFreeSpace(freeSpace);
    for (int i = 0; i < response.childrenSize(); i++) {
        TreeNode node = response.getChildren().get(i);
        if (node == null) {
            continue;
        }
        String levelName = node.getValue("open");
        if (levelName == null || levelName.trim().length() <= 0) {
            continue;
        }
        if (levelName.indexOf("level") >= 0) {
            String path = node.getValue("path");
            String size = node.getValue("size");
            String date = node.getValue("data");
            DbBackupHistoryInfo dbBackupHistoryInfo = new DbBackupHistoryInfo(levelName, path, size, date);
            dbBackupInfo.addDbBackupHistoryInfo(dbBackupHistoryInfo);
        }
    }
    return dbBackupInfo;
}
Also used : DbBackupHistoryInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DbBackupHistoryInfo) DbBackupInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DbBackupInfo) TreeNode(com.cubrid.cubridmanager.core.common.socket.TreeNode)

Example 3 with DbBackupHistoryInfo

use of com.cubrid.cubridmanager.core.cubrid.database.model.DbBackupHistoryInfo in project cubrid-manager by CUBRID.

the class GetDbBackupInfoTaskTest method testBackupExist.

public void testBackupExist() {
    if (StringUtil.isEqual(SystemParameter.getParameterValue("useMockTest"), "n"))
        return;
    System.out.println("<database.backupdbinfo.001.req.txt>");
    GetDbBackupInfoTask task = new GetDbBackupInfoTask(serverInfo);
    task.setDbName("demodb");
    task.execute();
    assertTrue(task.isSuccess());
    assertNull(task.getErrorMsg());
    DbBackupInfo info = task.getDbBackupInfo();
    assertNotNull(info);
    assertEquals("/opt/frameworks/cubrid2/databases/demodb/backup", info.getDbDir());
    assertEquals("15216", info.getFreeSpace());
    List<DbBackupHistoryInfo> list = info.getBackupHistoryList();
    assertNotNull(list);
    assertEquals(1, list.size());
    DbBackupHistoryInfo his = list.get(0);
    assertEquals("level0", his.getLevel());
    assertEquals("/opt/frameworks/cubrid2/databases/demodb/backup/demodb_backup_lv0", his.getPath());
    assertEquals("5256192", his.getSize());
    assertEquals("2009.06.26.22.37", his.getDate());
}
Also used : DbBackupHistoryInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DbBackupHistoryInfo) DbBackupInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DbBackupInfo)

Example 4 with DbBackupHistoryInfo

use of com.cubrid.cubridmanager.core.cubrid.database.model.DbBackupHistoryInfo in project cubrid-manager by CUBRID.

the class GetDbBackupInfoTaskTest method testNoBackup.

public void testNoBackup() {
    if (StringUtil.isEqual(SystemParameter.getParameterValue("useMockTest"), "n"))
        return;
    System.out.println("<database.backupdbinfo.002.req.txt>");
    GetDbBackupInfoTask task = new GetDbBackupInfoTask(serverInfo);
    task.setDbName("nobackupdb");
    task.execute();
    assertTrue(task.isSuccess());
    assertNull(task.getErrorMsg());
    DbBackupInfo info = task.getDbBackupInfo();
    assertNotNull(info);
    assertEquals("/opt/frameworks/cubrid2/databases/nobackupdb/backup", info.getDbDir());
    assertEquals("15216", info.getFreeSpace());
    List<DbBackupHistoryInfo> list = info.getBackupHistoryList();
    assertNotNull(list);
    assertEquals(0, list.size());
}
Also used : DbBackupHistoryInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DbBackupHistoryInfo) DbBackupInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DbBackupInfo)

Aggregations

DbBackupHistoryInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DbBackupHistoryInfo)4 DbBackupInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DbBackupInfo)3 TreeNode (com.cubrid.cubridmanager.core.common.socket.TreeNode)1 NumberFormat (java.text.NumberFormat)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1