再好的服务器都会出事,我们用的ibm的服务,有个客户的服务器在一周内出事8次,数据库的服务器出事,oracle中的数据全没有,我们备份的数据再数据库的机子上,结果机子起不来,后来为了防止机子再出现问题,我就再3个计算机上做备份,这样不会3个机子上都会出问题。不过问题又出来了,每天都备份再3个机子上,那么多备份的文件若不及时删掉,保留再机子也是特别占地方的。
我就写了个java程序,删除2天前的文件,然后再备份数据库,这样就不会很多数据库备份文件。
import java.io.File;
import java.util.Calendar;
public class BakDate {
String name[] = { "fzept", "ndept", "npept", "ptept", "lyept", "zzept" };
public static void main(String[] args) throws InterruptedException {
BakDate bakDate = new BakDate();
String file = "F:/wang/bat";
String file1 = "F:/wang";
bakDate.runbatFile(file);
bakDate.deleteOldFile(file1);
}
public void runbatFile(String strOldFilePath) {
try {
Runtime rt = Runtime.getRuntime();
Process ps = null;
String filename[] = new String[name.length];
for (int i = 0; i < name.length; i++) {
filename[i] = strOldFilePath + "/" + name[i] + ".bat";
ps = rt.exec("cmd.exe /C start " + filename[i]);
ps.waitFor();
}
} catch (Exception e) {
System.out.println("OracleTableChecker : rebuildDb Error!!!");
e.printStackTrace();
}
}
public void deleteOldFile(String strOldFilePath) {
Calendar today = Calendar.getInstance();
today.add(Calendar.DAY_OF_MONTH, -2);
String now = today.get(Calendar.YEAR) + "-"
+ (today.get(Calendar.MONTH) + 1) + "-"
+ today.get(Calendar.DATE);
String filename[] = new String[name.length];
for (int i = 0; i < name.length; i++) {
filename[i] = name[i] + now + ".DMP";
}
for (int i = 0; i < filename.length; i++) {
new File(strOldFilePath + "/" + filename[i]).delete();
}
}
}