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);
        }
        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);
        }
Ejemplo n.º 3
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);
        }