package com.wz.test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
public class DBTest {
public static void main(String[] args) {
BufferedReader buf = null;
Runtime run = Runtime.getRuntime();
//Windows远程备份MySqL
String[] cmd1 = new String[]{"cmd", "/c",
"C: && cd C:/Program Files/MySQL/MySQL Server 5.7/bin && "
+ "mysqldump -h192.168.1.242 -uroot -p123456 --verbose --databases erp > D:/logs/qq.sql"};
//Windows远程备份Oracle
String[] cmd2 = new String[]{"cmd", "/c",
"C: && cd D:/app/Administrator/product/11.2.0/dbhome_1/BIN && "
+ "exp wang/123456@192.168.1.242:1521/orcl file = D:/logs/qq.dmp"};
//Linux远程备份MySqL
String[] cmd3 = new String[]{"/bin/sh", "-c",
"mysqldump -h192.168.1.118 -uroot -p123456 --verbose --databases erp > /home/wangzi/tmp/pp.sql"};
//Linux远程备份Oracle
String[] cmd4 = new String[]{"/bin/sh", "-c",
"exp wang/123456@192.168.1.242:1521/orcl file = /home/wangzi/tmp/pp.dmp"};
try {
Process process = run.exec(cmd1);
buf = new BufferedReader(new InputStreamReader(process.getInputStream(),
Charset.forName("GBK")));
String line = null;
StringBuffer sb = new StringBuffer();
while ((line = buf.readLine()) != null) {
sb.append(line + "\n");
}
System.out.println(sb.toString());
} catch (IOException e) {
e.printStackTrace();
} finally {
if (buf != null) {
try {
buf.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
DB backup
最新推荐文章于 2024-04-05 09:47:32 发布