|
|
Anasayfa | Toplu SMS | Video | Web Hosting |
Makale Ara | Anketler | Sitene Ekle | RSS Kaynağı
|
|
|
c# ve vb.net mysql backup restore işlemleri
c# ve vb.net mysql backup restore işlemleri
Kategori |
: Asp.NET |
Yorum Sayısı |
: 0 |
Okunma |
: 239 |
Tarih |
: 28 Ekim 2009 21:42 |
Örnek 1 : MySql_Backup.bat @ECHO off cls set DBchoice=%1% set User=%2% set Password=%3% set pathchoice=%4%
@REM Remove double quotes from the path @REM SET pathchoice=%pathchoice:"=% @REM SET pathchoice=%pathchoice:"=%
mysqldump --add-drop-table -B %DBchoice% -u %User% --password=%Password% > %pathchoice%
MySql_Restore.bat @ECHO off cls
set User=%1% set Password=%2% set DBchoice=%3% set pathchoice=%4% set hostIP=%5% set toolPath=%6%
@REM Remove double quotes from the path @REM SET pathchoice=%pathchoice:"=% @REM SET pathchoice=%pathchoice:"=%
%toolPath%\mysql -u %User% -h%hostIP% --password=%Password% %DBchoice% < %pathchoice%
Create the following method to execute the batch files with proper parameters C#
/// /// Author : Himasagar Kutikuppala ///A utility method that runs the batch file with supplied arguments. /// /// /// /// protected bool ExecuteBatchFile(string batchFileName, string[] argumentsToBatchFile) { string argumentsString = string.Empty; try { //Add up all arguments as string with space separator between the arguments if (argumentsToBatchFile != null) { for (int count = 0; count < argumentsToBatchFile.Length; count++) { argumentsString += " "; argumentsString += argumentsToBatchFile[count]; //argumentsString += "\""; } }
//Create process start information System.Diagnostics.ProcessStartInfo DBProcessStartInfo = new System.Diagnostics.ProcessStartInfo(batchFileName, argumentsString);
//Redirect the output to standard window DBProcessStartInfo.RedirectStandardOutput = true;
//The output display window need not be falshed onto the front. DBProcessStartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; DBProcessStartInfo.UseShellExecute = false;
//Create the process and run it System.Diagnostics.Process dbProcess; dbProcess = System.Diagnostics.Process.Start(DBProcessStartInfo);
//Catch the output text from the console so that if error happens, the output text can be logged. System.IO.StreamReader standardOutput = dbProcess.StandardOutput;
/* Wait as long as the DB Backup or Restore or Repair is going on. Ping once in every 2 seconds to check whether process is completed. */ while (!dbProcess.HasExited) dbProcess.WaitForExit(2000);
if (dbProcess.HasExited) { string consoleOutputText = standardOutput.ReadToEnd(); //TODO - log consoleOutputText to the log file. }
return true; } // Catch the SQL exception and throw the customized exception made out of that catch (SqlException ex) { ExceptionManager.Publish(ex); throw SQLExceptionClassHelper.GetCustomMsSqlException(ex.Number); } // Catch all general exceptions catch (Exception ex) { ExceptionManager.Publish(ex); throw new CustomizedException(ARCExceptionManager.ErrorCodeConstants.generalError, ex.Message); } }
VB.NET - ''' <summary&RT;
- ''' Author : Himasagar Kutikuppala
- '''A utility method that runs the batch file with supplied arguments.
- ''' </summary&RT;
- ''' <param name="batchFileName"&RT;Name of the batch file that should be run</param&RT;
- ''' <param name="argumentsToBatchFile"&RT;Arguments to the batch file</param&RT;
- ''' <returns&RT;Status of running the batch file</returns&RT;
- Protected Function ExecuteBatchFile(ByVal batchFileName As String, ByVal argumentsToBatchFile As String()) As Boolean
- Dim argumentsString As String = String.Empty
- Try
-
- If argumentsToBatchFile IsNot Nothing Then
- For count As Integer = 0 To argumentsToBatchFile.Length - 1
- argumentsString += " "
-
- argumentsString += argumentsToBatchFile(count)
- Next
- End If
-
-
- Dim DBProcessStartInfo As New System.Diagnostics.ProcessStartInfo(batchFileName, argumentsString)
-
-
- DBProcessStartInfo.RedirectStandardOutput = True
-
-
- DBProcessStartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
- DBProcessStartInfo.UseShellExecute = False
-
-
- Dim dbProcess As System.Diagnostics.Process
- dbProcess = System.Diagnostics.Process.Start(DBProcessStartInfo)
-
-
- Dim standardOutput As System.IO.StreamReader = dbProcess.StandardOutput
-
-
-
-
- While Not dbProcess.HasExited
- dbProcess.WaitForExit(2000)
- End While
-
- If dbProcess.HasExited Then
-
-
- Dim consoleOutputText As String = standardOutput.ReadToEnd()
- End If
-
- Return True
- Catch ex As SqlException
-
-
- ExceptionManager.Publish(ex)
- Throw SQLExceptionClassHelper.GetCustomMsSqlException(ex.Number)
- Catch ex As Exception
-
- ExceptionManager.Publish(ex)
- Throw New CustomizedException(ARCExceptionManager.ErrorCodeConstants.generalError, ex.Message)
- End Try
- End Function
Örnek 2 : string cmdStr = "BACKUP DATABASE " + DatabaseName + " TO DISK = N'" + TempFolder + "\\" + DatabaseName + "_Backup.bak" + "' WITH NOFORMAT, INIT, NAME = N'" + DatabaseName + "-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10 ";
Örnek 3 : process.run("mysqldump.exe","--user=ADMIN --password=PASS db_try > c:/backup.sql");
but it doesnt work
and i also try to restore the database and i do this in the c:\> prompt and it works:
mysql -u ADMIN -pPASS db_try< c:/backup.sql
and when i try to do it with process.run("mysql.exe","-u ADMIN -pPASS db_try< c:/backup.sql");
Yazdırılabilir Sayfa |
Word'e Aktar |
Tavsiye Et
| Yorum Yaz
Asp.NET |
En Çok Okunan Makaleler |
|
|
|
|
Seçtiklerimiz
|
|
© 2004-2009 Tüm Hakları Saklıdır RSS Kaynağı
AltınSoft Bilişim Teknolojileri
Altyapı: MyDesign Haber Sistemi
|