总体思路是仿照网元向本地备份配置数据的工作流程。

前段---》服务器

DataExpDlg.java(L452)

DataExpImpInf.java(L290)

  public boolean execDataExport(String sFileName, String sDomainId,
      String sChassisId) throws Exception {
    boolean b = sessionClient.execDataExport(sDomainId, sChassisId, sFileName);
    return b;
  }
  public boolean execDataExportFtp(String sFileName, String sDomainId,
          String sChassisId) throws Exception {
        boolean b = sessionClient.execDataExportFtp(sDomainId, sChassisId, sFileName);
        System.out.println(b);
        return b;
      }
  

uEmsSessionClint.java(549)

 

    public boolean execDataExportFtp( String sDomainId, String sChassisId, String sBackupName ) throws Exception
    {
        return myDataInterface.execDataExportFtp( sDomainId, sChassisId, sBackupName );
    }

 

 

 

uCommonDataServerInterface .java(71)

 

    public boolean execDataImport( String sBackupName, String sDomainId, String sRackId, String sNewChassisId, Map newNeInfo, Map newPhysicalInfo ) throws Exception;
    public boolean execDataExport( String sDomainId, String sChassisId, String sBackupName ) throws Exception;
    public boolean execDataExportFtp( String sDomainId, String sChassisId, String sBackupName ) throws Exception;

 

uCommonDataServer.java(6786)

    public boolean execDataExportFtp(String sDomainId, String sChassisId,
            String sBackupName) throws Exception
{
        return myCommonDataServerUtil.execDataFtp(sDomainId, sChassisId, sBackupName);
}

uCommonDataServerUtil.java(1483)

    public boolean execDataFtp(String sDomainId, String sChassisId,
            String sBackupName) throws Exception {
        String sDomainID = sDomainId;
        // for Multi-Chassis Data Export, sChassisId may be "0" or "11,12"
        boolean bReturn = true;
        try {
            // getDomainIDByNeID

            String sNeID = "";
            // if domainID_neID, should split them, only export the neid's data
            // --add by lynn for UTEx
            if (sDomainId.indexOf("_") > 0) {
                sDomainID = sDomainId.substring(0, sDomainId.indexOf("_"));
                sNeID = sDomainId.substring(sDomainId.indexOf("_") + 1);
            }
            NmsLog.error(sLogFile, "execDataExport->sDomainID=" + sDomainID
                    + " sNeID=" + sNeID + " sChassisId=" + sChassisId);

            // ******************* for Combined NEs in one chassis ("combined"
            // means MG5.1 and CSP5.2 can be added in MS51_DOMAIN and share one
            // chassis) *******************
            // String[] asAllNe = NeUtil.getNEsInChassisByNeID(sNeId);
            // get all the NE_ID with rack, not include no rack NE
            String[] asAllNE = NeUtil.getNEsInChassis(sDomainID, sChassisId);

            if (asAllNE == null) {
                bReturn = false;
            } else {
                if (asAllNE.length == 0 && !sNeID.equals("")) { // only UTex NE,
                    // use neid
                    asAllNE = new String[]{sNeID};
                }
                int[] iNeCount = new int[sAllNeTypeArray.length];
                for (int i = 0; i < sAllNeTypeArray.length; i++) {
                    iNeCount[i] = 0;
                }
                for (int i = 0; i < asAllNE.length; i++) {
                    String sNE_ID = asAllNE[i];
                    String sNeType = NeUtil.getNeTypeByID(sNE_ID);
                    String sNeName = NeUtil.getNeNameByID(sNE_ID);

                    for (int j = 0; j < sAllNeTypeArray.length; j++) {
                        if (sNeType.equals(sAllNeTypeArray[j])) {
                            iNeCount[j]++;
                            sFilePath = sBackupDir
                                    + NeUtil.getDomainTypeByDomainID(sDomainID)
                                    + "/" + sBackupName + "/" + sNeType
                                    + iNeCount[j];

                            NmsLog.error(sLogFile,
                                    "11111111111111111111111111111111111111备份的目录:"
                                            + sFilePath);

                            break;
                        }
                    }

                    String asFailedTables[] = this.backupPreDateByFilePath(
                            sNE_ID, sFilePath);
                    if (asFailedTables == null) {
                        NmsLog.error(sLogFile,
                                "execDataExport() -> #################### BACKUP_Multi_NE_FAILED:  NE"
                                        + (i + 1) + ": " + sNeName + " ("
                                        + sNeType + ")");
                        bReturn = false;
                    } else if (asFailedTables.length == 0) {
                        NmsLog.error(sLogFile,
                                "execDataExport() -> #################### BACKUP_Multi_NE_SUCCESS: NE"
                                        + (i + 1) + ": " + sNeName + " ("
                                        + sNeType + ")");
                    } else {
                        String sFailedTables = "";
                        for (int j = 0; j < asFailedTables.length; j++) {
                            sFailedTables += "(" + (j + 1) + ") "
                                    + asFailedTables[j] + "  ";
                        }
                        NmsLog.error(sLogFile,
                                "execDataExport() -> #################### BACKUP_Multi_NE_FAILED: NE"
                                        + (i + 1) + ": " + sNeName + " ("
                                        + sNeType + ")  Failed Tables: "
                                        + sFailedTables);
                        bReturn = false;
                    }

                    // backup NeInfo to file
                    String sNeInfoKeyName = "utsSpecialNeEntity";
                    String sNeInfoFileName = sFilePath + "/" + sNeInfoKeyName
                            + ".csv";
                    boolean bNeInfoSuccess = this.backupPreDataByFileName(
                            sNE_ID, sNeInfoKeyName, sNeInfoFileName);
                    if (!bNeInfoSuccess) {
                        NmsLog
                                .error(
                                        sLogFile,
                                        "execDataExport() -> #################### backup NeInfo failed!!! ####################");
                        bReturn = false;
                    }

                }
                if (sNeID.equals("")) // only for rack ne
                {
                    // backup domain data of specified ChassidID to file
                    String[] asDomainKeyName = {
                            "domain_utsComNeGenCfgChaTable",
                            "domain_utsComNeGenCfgBrdTable"};
                    for (int i = 0; i < asDomainKeyName.length; i++) {
                        String sDomainDataFileName = sBackupDir
                                + NeUtil.getDomainTypeByDomainID(sDomainID)
                                + "/" + sBackupName + "/" + asDomainKeyName[i]
                                + ".csv";
                        boolean bChassisDataSuccess = this
                                .backupDomainDataByFileNameByCha(sDomainID,
                                        asDomainKeyName[i],
                                        sDomainDataFileName, sChassisId);
                        if (!bChassisDataSuccess) {
                            NmsLog
                                    .error(
                                            sLogFile,
                                            "execDataExport() -> #################### backup domain data failed!!! ####################");
                            bReturn = false;
                        }
                    }
                }
            }
        } catch (Exception e) {
            NmsLog.error(NmsLog.SYSTEM_ERR_FILE, e);
            NmsLog.error(sLogFile, "execDataExport() -> Exception occurred: "
                    + NeUtil.getExceptionString(e));
            bReturn = false;
        }

        // 登录到ftp服务器

        String host = "";
        String id = "";
        String pw = "";
        String path = "";

        SAXReader reader = new SAXReader();
        Document doc = null;
        try {
            doc = reader.read(new File(
                    "/opt/wacos/server/nms/WebNMS/conf/wacos/backup.xml"));
            Element rootElement = doc.getRootElement();
            for (Iterator se = rootElement.elementIterator(); se.hasNext();) {
                Element seElement = (Element) se.next();
                host = seElement.element("hostName").getTextTrim();
                id = seElement.element("ftpLogin").getTextTrim();
                pw = seElement.element("ftpPassword").getTextTrim();
                path = seElement.element("filePath").getTextTrim();
                NmsLog.error(sLogFile, "3333333333333333333333333333登录信息验证:"
                        + host + ":" + id + ":" + pw + ":" + path);

                FTPClient ftp = new FTPClient(host);
                ftp.login(id, pw);
                uploadDir(path, ftp);
                ftp.quit();

            }
        } catch (DocumentException e1) {
            e1.printStackTrace();
        }

        return bReturn;
    }
    List<String> Ftplist=new ArrayList<String>();
    public void uploadDir(String path, FTPClient ftp) throws IOException,
            FTPException {
    try {    
        
        int m=0;
            ftp.chdir(path);
            // 获取远程主机当前文件夹
            //NmsLog.error(sLogFile, "currentDir:" + path);
            // 获取本地文件夹下的信息
            File file = new File(path);
            String filename[] = file.list();
//这个for循环是为了将文件和文件夹同时存在的情况下,强行将文件在数组中的位置提前
//因为如果不提前的话,可能先读取了文件夹,导致递归的目录递进(tempath),从而无法读取与之同级的文件。
for (int q= 0; q< filename.length; q++) { if(filename[q].indexOf(".csv")>-1){ String tt=null; tt=filename [m]; filename[m]=filename[q]; filename[q]=tt; m++; } } int i; boolean n = false; for ( i= 0; i < filename.length; i++) { String tempath=path+"/"+filename[i]; if (filename[i].indexOf(".csv")==-1) { NmsLog.error(sLogFile,"已经创建的文件目录:"+Ftplist.toString()); NmsLog.error(sLogFile,"ftp创建文件的当前目录"+ftp.pwd()+":::"+"要创建的目录名:"+filename[i]); //这里的Ftplist集合里面存放已经创建的文件夹目录全称(因为仅仅是文件夹名字不能保证唯一性),防止在远端重复创建目录。
            //但是有个隐患,这个Ftplist会不会无限增长,导致一些问题呢。(刚才发现确实存在问题,如果程序重启的话,Ftplist里面的数据就会丢掉,所以这种方法不行) //
if(!Ftplist.contains(tempath)){ //ftp.mkdir(filename[i]); //}else{ // continue; //}
              //这里递归调用uploadDir方法 // uploadDir(tempath, ftp); //
boolean alan=Ftplist.add(tempath); // NmsLog.error(sLogFile,"往集合里面添加文件目录:"+tempath+"是否成功:"+alan);

          //换另一种方法,如果ftp远端备份重复的文件就会抛出异常,直接捕获这个异常就好了,妈的!!!!

          try {
              ftp.mkdir(filename[i]);
              uploadDir(tempath, ftp);

            } catch (Exception e) {

            //NmsLog.error(sLogFile,"文件夹创建失败,因为已经存在");
        }


}
else { tempath=path+"/"+filename[i]; NmsLog.error(sLogFile, "ftp文件的过程tempath:"+tempath+":::::"+"filename[i]:::"+filename[i]+":::"+"当前ftp目录:"+ftp.pwd()); ftp.put(tempath, filename[i]); }
//在结束当前循环的时候向外退出一层目录
int qq= tempath.indexOf(filename[i]); String ww=tempath.substring(0,qq); ftp.chdir(ww); } } catch (com.utstar.ems.omcs.common.net.ftp.FTPException ftpex1) { NmsLog.error(sLogFile, "a Ftp error:" + ftpex1.getMessage()); } catch (Exception err1) { NmsLog.error(sLogFile, "other Error is :" + err1); } }