DB backup

来源:互联网 发布:四川广电网络在线直播 编辑:程序博客网 时间:2024/05/21 18:48
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远程备份MySqLString[] 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远程备份OracleString[] 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远程备份MySqLString[] cmd3 = new String[]{"/bin/sh", "-c","mysqldump -h192.168.1.118 -uroot -p123456 --verbose --databases erp > /home/wangzi/tmp/pp.sql"};//Linux远程备份OracleString[] 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();}}}}}


0 0
原创粉丝点击