public void copyLogs()

in src/main/java/co/elastic/support/util/RemoteSystem.java [155:192]


    public void copyLogs(List<String> entries, String logDir, String targetDir) {

        ChannelSftp channelSftp = null;
        String tempDir = "templogs";
        String mkdir = "mkdir templogs";
        String copy = " cp '{{LOGPATH}}/{{FILENAME}}'  '{{TEMP}}/{{FILENAME}}'";
        copy = copy.replace("{{LOGPATH}}", logDir);
        copy = copy.replace("{{TEMP}}", tempDir);
        // Because logs are only available to the elasticsearch user, other accounts with access,
        // or sudo, we need to copy them into the home directory of the account being used. If sudo was
        // specified or the appropriate account level it will work. If not, we would have gotten an empty
        // file listing and exited by now.
        try {
            runCommand(mkdir);
            for(String filename : entries){
                String cmd = copy.replace("{{FILENAME}}", filename);
                runCommand(cmd);
            }

            // Now they have been moved from the log directory into the temp dir created in the user's home
            // we can move them to the the calling host. It should pull them all in one pass.
            channelSftp = (ChannelSftp) session.openChannel("sftp");
            channelSftp.connect();
            channelSftp.get("templogs/*", targetDir);
            channelSftp.exit();

            // clean up the temp logs on the remote host
            runCommand(" rm -Rf templogs");

        } catch (Exception e) {
            logger.info(Constants.CONSOLE, "Error occurred copying remote logfiles. {}", Constants.CHECK_LOG);
            logger.error( e);
        } finally {
            if(channelSftp != null && channelSftp.isConnected()){
                channelSftp.disconnect();
            }
        }
    }