Exemplo n.º 1
0
    protected void btnBackup_Click(object sender, EventArgs e)
    {
        DateTime fileDateTime = AppUtils.ServerDateTime();
        string   strTempPath  = HROne.Common.Folder.GetOrCreateSessionTempFolder(Session.SessionID).FullName;
        string   databaseFile = System.IO.Path.Combine(strTempPath, "HROne_" + fileDateTime.ToString("yyyyMMddHHmmss") + ".bak");
        string   errorMessage = string.Empty;

        AppUtils.BackUpDatabase(dbConn, databaseFile, out errorMessage);
        if (System.IO.File.Exists(databaseFile))
        {
            System.IO.FileInfo sourceFileInfo     = new System.IO.FileInfo(databaseFile);
            string             destinationZipFile = System.IO.Path.Combine(strTempPath, "HROne_" + fileDateTime.ToString("yyyyMMddHHmmss") + ".zip");
            zip.Compress(strTempPath, sourceFileInfo.Name, destinationZipFile, ZipPassword.Text);
            sourceFileInfo.Delete();
            if (System.IO.File.Exists(destinationZipFile))
            {
//                WebUtils.RegisterDownloadFileJavaScript(this, destinationZipFile, "HROne_" + fileDateTime.ToString("yyyyMMddHHmmss") + ".zip", true, 0);
                WebUtils.TransmitFile(this.Response, destinationZipFile, "HROne_" + fileDateTime.ToString("yyyyMMddHHmmss") + ".zip", true);
            }
        }
        else
        {
            PageErrors errors = PageErrors.getErrors(HROne.Lib.Entities.ESystemParameter.db, Page.Master);
            if (errors != null)
            {
                errors.addError(errorMessage);
            }
        }
    }
Exemplo n.º 2
0
    private static bool AutoBackUpDatabase(DatabaseConnection dbConn, string VersionNo)
    {
        string filePath = string.Empty;

        if (dbConn.dbType == DatabaseConnection.DatabaseType.MSSQL)
        {
            System.Data.SqlClient.SqlConnection conn = (System.Data.SqlClient.SqlConnection)dbConn.Connection;
            filePath = conn.Database + "_" + VersionNo + "_" + AppUtils.ServerDateTime().ToString("yyyyMMddHHmmss") + ".bak";
        }
        return(AppUtils.BackUpDatabase(dbConn, filePath, out strLastErrorMessage));
        //if (perspectivemind.common.DBUtil.type is perspectivemind.common.SQLType)
        //{
        //    System.Data.SqlClient.SqlConnection conn = (System.Data.SqlClient.SqlConnection)perspectivemind.common.DBUtil.getConnection();
        //    string backupSQL = "BACKUP DATABASE " + conn.Database + "\r\n" +
        //        "TO DISK='" + conn.Database + "_" + VersionNo + "_" + AppUtils.ServerDateTime().ToString("yyyyMMddHHmmss") + ".bak'";
        //    if (AppUtils.DBPatch(backupSQL, out strLastErrorMessage))
        //    {
        //        return true;
        //    }
        //}
        //return false;
    }