Import Java. io. bufferedreader; import Java. io. file; import Java. io. inputstreamreader; import Java. text. simpledateformat; import Java. util. date; public class backdatahelper {private string sqlpath = "C: \ mysql \ bin \"; private string username = "user1"; private string Password = "123456 "; private string dataname = "datatest"; private string Foldername; private string backpath; private string IP = "127.0.0.1"; PRI Vate string port = "3306"; Public String getbackpath () {return backpath;} public void setbackpath (string backpath) {This. backpath = backpath;} Public String getfoldername () {return Foldername;} public void setfoldername (string Foldername) {This. foldername = Foldername;} Public String getdataname () {return dataname;} public void setdataname (string dataname) {This. dataname = dataname;} pub LIC string getsqlpath () {return sqlpath;} public void setsqlpath (string sqlpath) {This. sqlpath = sqlpath;} Public String getip () {return IP;} public void setip (string IP) {This. IP = IP;} Public String getport () {return port;} public void setport (string port) {This. port = port;} public backdatahelper (string sqlpath, string IP, string port, string backpath) {This. sqlpath = sqlpath; this. IP = IP; This. port = port; this. foldername = getdatetime (new date (); this. backpath = backpath;} public backdatahelper (string sqlpath, string IP, string port, string dataname, string backpath) {This. sqlpath = sqlpath; this. IP = IP; this. port = port; this. dataname = dataname; this. foldername = getdatetime (new date (); this. backpath = backpath;} public backdatahelper (string backpath) {This. foldername = getdatetime (new date ()); This. backpath = backpath;} private string getdatetime (date) {simpledateformat df = new simpledateformat ("yyyy-MM-dd_HHmmss"); string returnvalue = ""; if (date! = NULL) {returnvalue = DF. format (date);} return (returnvalue);}/*** backup */Public void executexport () throws exception {string Path = This. backpath + "\" + this. foldername; file = new file (PATH); If (! File. exists () {file. mkdirs ();} string datapath = path + "\ data. SQL "; string exec =" CMD/C "+ this. sqlpath + "mysqldump.exe" + "-U" + this. username + "" + "-P" + this. password + "" + "-h" + this. IP + "" + "-P" + this. port + "" + dataname + "" + ">" + datapath; process P = runtime.getruntime(.exe C (EXEC); bufferedreader BR = new bufferedreader (New inputstreamreader (P. getinputstream (); string R Eadline = Br. Readline (); While (Readline! = NULL) {Readline = Br. Readline ();} If (BR! = NULL) {BR. close ();} generatekey. createencrypt (datapath); Exec = "xcopy D: \ wwwroot \" + this. dataname + "\ product \\*. * "+ path +" \ product \\*. */E "; P = runtime.getruntime(cmd.exe C (EXEC); BR = new bufferedreader (New inputstreamreader (P. getinputstream (); Readline = BR. readline (); While (Readline! = NULL) {Readline = Br. Readline ();} If (BR! = NULL) {BR. close () ;}/ *** restore */Public void executimport (string path) throws exception {string temppath = path + "\" + "temp_data. SQL"; generatekey. createdatadecrypt (path + "\ data. SQL ", temppath); string exec =" CMD/C "+ this. sqlpath + "mysql.exe" + "-U" + this. username + "" + "-P" + this. password + "" + "-h" + "" + this. IP + "" + this. dataname + "" + "<" + temppath; process P = runtime. Getruntime(cmd.exe C (EXEC); bufferedreader BR = new bufferedreader (New inputstreamreader (P. getinputstream (); string Readline = Br. Readline (); While (Readline! = NULL) {Readline = Br. Readline ();} If (BR! = NULL) {BR. close ();} file F1 = new file (temppath); If (f1.isfile () {f1.delete ();} exec = "xcopy" + path + "\ product \\*. * D: \ wwwroot \ "+ this. dataname + "\ product \\*. */E "; P = runtime.getruntime(cmd.exe C (EXEC); BR = new bufferedreader (New inputstreamreader (P. getinputstream (); Readline = BR. readline (); While (Readline! = NULL) {Readline = Br. Readline ();} If (BR! = NULL) {BR. close () ;}} public static void main (string [] ARGs) {try {generatekey. getgeneratekey (); backdatahelper BdH = new backdatahelper ("d :\\ wwwroot \ test \ dbbackup"); // bdh.exe cutexport (); bdh.exe cutimport ("D: \ wwwroot \ test \ dbbackup \ 2012-11-19_143339 ");} catch (exception e) {e. printstacktrace ();}}}