示例#1
0
        public void makeBackup()
        {
            _sBaseState = false;
            MySqlConnection _oConn = new MySqlConnection(_sConnectionString);

            _oConn.Open();
            if (_oConn.State == System.Data.ConnectionState.Open)
            {
                _sBaseState = true;

                DateTime backupTime = DateTime.Now;
                int      year       = backupTime.Year;
                int      month      = backupTime.Month;
                int      day        = backupTime.Day;

                String sBackupFile = backupTime.ToString();
                sBackupFile = _sSciezkaDoKataloguZkopiami + @"\" + year + "-" + month + "-" + day + "_" + sBazaDanych + ".sql";

                IConnect oBackup = new mysql();
                oBackup.sConnectionString = _sConnectionString;
                oBackup.sBackupFileName   = sBackupFile;
                oBackup.Open();
                if (oBackup.State == System.Data.ConnectionState.Open)
                {
                    oBackup.createBackup();
                    oBackup.Close();

                    StreamReader oRead        = new StreamReader(sBackupFile);
                    FileStream   oStream      = new FileStream(sBackupFile + @".zip", FileMode.Create, FileAccess.Write);
                    GZipStream   oCompression = new GZipStream(oStream, CompressionMode.Compress);
                    StreamWriter oWrite       = new StreamWriter(oCompression);
                    oWrite.Write(oRead.ReadToEnd());
                    oWrite.Close();
                    oRead.Close();
                    FileInfo oFile = new FileInfo(sBackupFile);
                    oFile.Delete();
                }
            }
        }