达梦数据库还原

逻辑导入主要使用dimp命令

  四种级别的导入命令如下:

  FULL: ./dimp USERID=SYSDBA/SYSDBA FILE=/mnt/data/dexp/db_str.dmp LOG=db_str.log FULL=Y  DIRECTORY=/mnt/data/dimp

  OWNER: ./dimp USERID=SYSDBA/SYSDBA FILE=/mnt/data/dexp/db_str.dmp LOG=db_str.log  OWNER=USER01 DIRECTORY=/mnt/data/dimp

  SCHEMAS: ./dimp USERID=SYSDBA/SYSDBA FILE=/mnt/data/dexp/db_str.dmp LOG=db_str.log SCHEMAS=USER01 DIRECTORY=/mnt/data/dimp

  TABLES: ./dimp USERID=SYSDBA/SYSDBA FILE=/mnt/data/dexp/db_str.dmp LOG=db_str.log TABLES=table1,table2 DIRECTORY=/mnt/data/dimp

远程导入文件命令:sshpass -p pwd  scp -P 22 username@远程ip:/opt/data/test1.dmp + 本地存放目录

以tables级别为例:

在备份是已将备份文件名和等备份信息保存到数据库,还原时通过记录id查询到备份信息拼接语句。

 public String recover(Map param) {
        String result = "";
        String copyType = param.get(“type”);
        Map map = new HashMap<>();
        Connection conn = DMruntimeUtil.login(ip, userName, userPwd);
        String filename = param.getWjmc();
        if (param.get(“tids”) == "") {
            //全部恢复
        } else {
            //部分恢复
            // 根据tids拼接表名
            List bfbList = bfbMapper.getTables(param.getTids().toString().split(","));
            if (bfbMapper == null || bfbList.size() == 0) {
                return null;
            }
            
            String tnames = param.get("tnames");
            String dexpStr = "";

            // 恢复命令./dimp USERID=SYSDBA/SYSDBA FILE=/mnt/data/dexp/db_str.dmp LOG=db_str.log
            // DIRECTORY=/mnt/data/dimp
            dexpStr = DMruntimeUtil.dimpByTables(hostip, dbname, username, password, filename, tnames);
            if (copyType.equals("本地")) {
                String cmd = "cd /opt/dameng/dmdbms/bin;" + dexpStr;
                result = DMruntimeUtil.execute(conn, cmd);
            } else if (copyType.equals("异域")) {
                // sshpass -p pwd scp -P 22 root@ip:/opt/data/test1.dmp
                // /opt/dameng/dmdbms/dm7data/EVAL/dexp/
                String cmd = "sshpass -p  " + param.getRepassword() + " scp -P " + param.getPort() + " "
                        + param.getUsername() + "@" + param.getIp() + ":" + param.getDir() + "/" + filename
                        + " /opt/dameng/dmdbms/dm7data/EVAL/dexp/;cd /opt/dameng/dmdbms/bin;" + dexpStr;
                result = DMruntimeUtil.execute(conn, cmd);
            }
        }
        return result;
    }

你可能感兴趣的:(达梦数据库还原)