项目中的log日志只保留12天,我想找到指定3天内的日志并打成tar包.
log文件路径
final String logFilePath = File.separator + "dat" + File.separator + "log" + File.separator + "localserver";
tar包名称
finl String logTarName = File.separator + "tmp" + File.separator + "LocalServerLog.tar.gz";
final String cmdStr = "find " + logFilePath + " -type f -name \"log.debug*\" -mtime -3 | xargs tar -czf " + logTarName;
execShell(cmdStr);//若返回0,则 成功
public static int execShell(String shell) {
Process process = null;
try {
process = Runtime.getRuntime().exec(
new String[] { "sh", "-c", shell });
return process.waitFor();
} catch (Exception e) {
e.printStackTrace();
return -1;
} finally {
if (process != null)
try { process.destroy(); } catch(Exception e) {}
}
}