SimpleDateFormat SDF = new SimpleDateFormat ("Yyyymmddhhmmss");
try {
String name = Sdf.format (new Date ());
String FilePath = System.getproperty ("User.dir") + "//" + name + ". SQL";
System Actuators
Runtime RT = Runtime.getruntime ();
Export Database Statements
StringBuffer cmd = new StringBuffer ();
Cmd.append ("Mysqldump-u");
Cmd.append (Serveconfig.dbuser);
Cmd.append ("-P");
Cmd.append (Serveconfig.dbpass);
Cmd.append ("--set-charset=utf8");
Cmd.append (Serveconfig.dbname);
Perform an export to get the input stream
Process child = Rt.exec (cmd.tostring ());
InputStream in = Child.getinputstream ();
InputStreamReader ir = new InputStreamReader (in, "UTF8");
Output file
FileOutputStream fo = new FileOutputStream (FilePath);
OutputStreamWriter OS = new OutputStreamWriter (FO, "UTF8");
Start reading data
char[] temp = new char[1024000];
int len = 0;
while (len = ir.read (temp)) > 0) {
Os.write (temp, 0, Len);
Os.flush ();
}
Don't forget to close the input and output stream
In.close ();
Ir.close ();
Os.close ();
Fo.close ();
Send a file to the backup server
FileUpLoad upload = Fileupload.createfileupload (serveconfig.backaddr, New File (FilePath));
Upload.trystart ();
Upload.waitfinish ();
Upload.doclose ();
} catch (Exception e) {
E.printstacktrace ();
}