昨天花了一個多小時寫的一個小東西,可能以前有很多人寫過了,不過還是放上來看看
備份,可以實現在應用程序文件夾內生成一個DataBaseBak文件夾,并把dmp文件按照時間來保存在這個文件夾內,我設的精度是分鐘,可以自行更改,異常寫入系統日志:
string startpath = Application.StartupPath;
DirectoryInfo di = new DirectoryInfo(startpath+"\\DataBaseBak");
di.Create();
string oraPath = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Oracle").GetValue("ORACLE_HOME").ToString();
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.FileName = oraPath +"\\bin\\EXP.exe";
proc.StartInfo.Arguments = " username/password@servicename file="+di.FullName+"\\filename"+DateTime.Now.ToString("yyyy-MM-dd-HH-mm")+".dmp owner=username";
proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
this.Cursor = Cursors.WaitCursor;
try
{
proc.Start();
MessageBox.Show("數據庫備份成功","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch(Exception ee)
{
MessageBox.Show("數據庫備份失敗","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
EventLog newLog=new EventLog();
newLog.Source = "OracleErr";
newLog.WriteEntry(ee.Message,System.Diagnostics.EventLogEntryType.Error);
}
finally
{
proc.Dispose();
}
this.Cursor = Cursors.Arrow;
恢復,可以自動定位到DataBaseBak文件夾,然后自行選擇需要的dmp文件,進行恢復,并將異常寫入系統日志:
OpenFileDialog selectDMPDialog = new OpenFileDialog();
selectDMPDialog.InitialDirectory = Application.StartupPath + "\\DataBaseBak";
selectDMPDialog.Filter = "備份文件(*.dmp)|*.dmp";
if(selectDMPDialog.ShowDialog() == DialogResult.OK)
{
string oraPath = Registry.LocalMachine.OpenSubKey("software").OpenSubKey("Oracle").GetValue("ORACLE_HOME").ToString();
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.FileName = oraPath+"\\bin\\IMP.exe";
proc.StartInfo.Arguments = " username/password@servicename file="+selectDMPDialog.InitialDirectory+"\\"+selectDMPDialog.FileName+" fromuser=username";
proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
this.Cursor = Cursors.WaitCursor;
try
{
proc.Start();
MessageBox.Show("數據庫導入成功","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch(Exception ee)
{
MessageBox.Show("數據庫備份失敗","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
EventLog newLog=new EventLog();
newLog.Source = "OracleErr";
newLog.WriteEntry(ee.Message,System.Diagnostics.EventLogEntryType.Error);
}
finally
{
proc.Dispose();
}
this.Cursor = Cursors.Arrow;
