Beispiel #1
0
        protected override OrganizationBackupRuntimeData ExecuteInternal(OrganizationBackupRuntimeData runtimeData, Guid orgId, Guid backupId, Guid queueItemId)
        {
            Exceptions.ThrowIfNullOrEmpty(runtimeData.RestoreSqlServerName, "runtimeData.RestoreSqlServerName");
            Exceptions.ThrowIfNullOrEmpty(runtimeData.RestoredDBName, "runtimeData.RestoredDBName");

            try
            {
                // drop restored db
                SqlUtility.DropDatabase(runtimeData.RestoreSqlServerName, runtimeData.RestoredDBName);
            }
            catch (SqlException ex)
            {
                // error 3701: database not found. If database is not found, we don't need to do anything.
                // Re-throw the exception for other type of exceptions, so executor can retry
                if (ex.Number != 3701)
                {
                    throw;
                }
            }

            // update restore sql server name and restored db name
            runtimeData.RestoreSqlServerName = null;        // clear restore sql server name
            runtimeData.RestoredDBName       = null;        // clear restore db name
            UpdateRuntimeData(queueItemId, runtimeData);

            return(runtimeData);
        }
        protected override OrganizationBackupRuntimeData ExecuteInternal(OrganizationBackupRuntimeData runtimeData, Guid orgId, Guid backupId, Guid queueItemId)
        {
            Exceptions.ThrowIfNullOrEmpty(runtimeData.RestoreSqlServerName, "runtimeData.RestoreSqlServerName");
            Exceptions.ThrowIfNullOrEmpty(runtimeData.RestoredDBName, "runtimeData.RestoredDBName");

            string orgUniqueName = LocatorService.Instance.GetOrganizationName(orgId);

            // Get the path to the file share from ServerSettingProperties table DataFilePath row
            string fileSharePath = (string)LocatorService.Instance.GetSiteSetting("DataFilePath");

            // compression backup
            CrmOrganizationBackupData backupData = SqlBackupRestoreUtility.ExecuteBackupSqlCommandByOrg(SqlBackupRestoreUtility.DatabaseBackupType.Compression, fileSharePath, runtimeData.RestoreSqlServerName, runtimeData.RestoredDBName, orgUniqueName);

            // update backup path, completion time and expiration time
            PropertyBag updateBag = new PropertyBag();

            updateBag["BackupPath"]     = backupData.BackupPathOnShare;
            updateBag["CompletionDate"] = DateTime.UtcNow;
            updateBag["ExpirationDate"] = ((DateTime)updateBag["CompletionDate"]).AddDays(GetExpirationDays(orgId));

            PropertyBag condition = new PropertyBag();

            condition["Id"] = backupId;
            using (IDatabaseService service = ConfigurationDatabaseService.NewService())
            {
                service.Update("OrganizationBackupData", updateBag, new PropertyBag[] { condition });
            }

            return(runtimeData);
        }
Beispiel #3
0
        public OrganizationBackupRuntimeData Execute(OrganizationBackupRuntimeData runtimeData, Guid orgId, Guid backupId, Guid queueItemId)
        {
            Exceptions.ThrowIfNull(runtimeData, "runtimeData");
            Exceptions.ThrowIfGuidEmpty(orgId, "orgId");
            Exceptions.ThrowIfGuidEmpty(backupId, "backupId");
            Exceptions.ThrowIfGuidEmpty(queueItemId, "queueItemId");

            // update status code in the table
            UpdateStatus(backupId, Step);

            return(ExecuteInternal(runtimeData, orgId, backupId, queueItemId));
        }
        protected override OrganizationBackupRuntimeData ExecuteInternal(OrganizationBackupRuntimeData runtimeData, Guid orgId, Guid backupId, Guid queueItemId)
        {
            Guid orgScaleGroupId = LocatorService.Instance.GetOrganizationScaleGroupId(orgId);

            // full backup
            CrmOrganizationBackupData backupData = SqlBackupRestoreUtility.ExecuteBackupSqlCommand(orgId, orgScaleGroupId);

            // update backup path and log path in runtime data
            runtimeData.BackupPath = backupData.BackupPathOnShare;
            runtimeData.LogPath    = backupData.LogPathOnShare;
            QueueManager.NewManager().UpdateQueueItemRuntimeData(queueItemId, OrganizationBackupRuntimeData.Serialize(runtimeData));
            return(runtimeData);
        }
        protected override OrganizationBackupRuntimeData ExecuteInternal(OrganizationBackupRuntimeData runtimeData, Guid orgId, Guid backupId, Guid queueItemId)
        {
            // delete initial full backup file and log file
            DeleteIfNotNull(runtimeData.BackupPath);
            DeleteIfNotNull(runtimeData.LogPath);

            // update backup path and log path in runtime data
            runtimeData.BackupPath = null;           // clear backup path
            runtimeData.LogPath    = null;           // clear log path
            UpdateRuntimeData(queueItemId, runtimeData);

            return(runtimeData);
        }
Beispiel #6
0
        protected override OrganizationBackupRuntimeData ExecuteInternal(OrganizationBackupRuntimeData runtimeData, Guid orgId, Guid backupId, Guid queueItemId)
        {
            Exceptions.ThrowIfNullOrEmpty(runtimeData.BackupPath, "runtimeData.BackupPath");

            string orgUniqueName = LocatorService.Instance.GetOrganizationName(orgId);

            // retrieve restore sql server name and generate restored db name
            if (string.IsNullOrEmpty(runtimeData.RestoreSqlServerName) || string.IsNullOrEmpty(runtimeData.RestoredDBName))
            {
                runtimeData.RestoreSqlServerName = RetrieveRestoreSqlServer();
                runtimeData.RestoredDBName       = orgUniqueName + "_" + Guid.NewGuid().ToString();
            }

            // update run time data with RestoreSqlServerName and RestoredDBName
            QueueManager.NewManager().UpdateQueueItemRuntimeData(queueItemId, OrganizationBackupRuntimeData.Serialize(runtimeData));

            // restore
            SqlBackupRestoreUtility.ExecuteRestoreSqlCommand(runtimeData.RestoreSqlServerName, runtimeData.RestoredDBName, runtimeData.BackupPath, null);

            return(runtimeData);
        }
        protected override OrganizationBackupRuntimeData ExecuteInternal(OrganizationBackupRuntimeData runtimeData, Guid orgId, Guid backupId, Guid queueItemId)
        {
            Exceptions.ThrowIfNullOrEmpty(runtimeData.RestoreSqlServerName, "runtimeData.RestoreSqlServerName");
            Exceptions.ThrowIfNullOrEmpty(runtimeData.RestoredDBName, "runtimeData.RestoredDBName");

            string sqlConnectionString = "Data Source=" + runtimeData.RestoreSqlServerName + ";Initial Catalog=" + runtimeData.RestoredDBName + ";Integrated Security=SSPI";

            using (SqlConnection connection = new SqlConnection(sqlConnectionString))
            {
                try
                {
                    connection.Open();

                    foreach (string fileName in L2OPScriptFileList.L2OPScripts)
                    {
                        ScriptExecutor.ExecuteScript(fileName, connection);
                    }

                    connection.Close();

                    // Must clear the pool, otherwise get "database currently in use" error when try to drop db.
                    SqlConnection.ClearPool(connection);
                }
                catch (SqlException)
                {
                    connection.Close();
                    SqlConnection.ClearPool(connection);
                    throw;
                }
                finally
                {
                    connection.Close();
                    SqlConnection.ClearPool(connection);
                }
            }

            return(runtimeData);
        }
Beispiel #8
0
 protected static void UpdateRuntimeData(Guid queueItemId, OrganizationBackupRuntimeData runtimeData)
 {
     QueueManager.NewManager().UpdateQueueItemRuntimeData(queueItemId, OrganizationBackupRuntimeData.Serialize(runtimeData));
 }
Beispiel #9
0
 protected abstract OrganizationBackupRuntimeData ExecuteInternal(OrganizationBackupRuntimeData runtimeData, Guid orgId, Guid backupId, Guid queueItemId);
Beispiel #10
0
 public static string Serialize(OrganizationBackupRuntimeData runtimeData)
 {
     return(CrmLiveSerializer.Object2Xml <OrganizationBackupRuntimeData>(runtimeData, false));
 }