private void ReadSetupValuesFromDocument()
		{
			using (LogContext.WithDatabase(Database.Name))
			{
				try
				{
					// Not having a setup doc means this DB isn't enabled for periodic exports
					var document = Database.Documents.Get(PeriodicExportSetup.RavenDocumentKey, null);
					if (document == null)
					{
						exportConfigs = null;
						exportStatus = null;
						return;
					}

					var status = Database.Documents.Get(PeriodicExportStatus.RavenDocumentKey, null);

					exportStatus = status == null ? new PeriodicExportStatus() : status.DataAsJson.JsonDeserialization<PeriodicExportStatus>();
					exportConfigs = document.DataAsJson.JsonDeserialization<PeriodicExportSetup>();


					awsAccessKey = Database.Configuration.Settings["Raven/AWSAccessKey"];
					awsSecretKey = Database.Configuration.Settings["Raven/AWSSecretKey"];
					azureStorageAccount = Database.Configuration.Settings["Raven/AzureStorageAccount"];
					azureStorageKey = Database.Configuration.Settings["Raven/AzureStorageKey"];

					if (exportConfigs.IntervalMilliseconds.GetValueOrDefault() > 0)
					{
						var interval = TimeSpan.FromMilliseconds(exportConfigs.IntervalMilliseconds.GetValueOrDefault());
						logger.Info("Incremental periodic export started, will export every" + interval.TotalMinutes + "minutes");

						var timeSinceLastBackup = SystemTime.UtcNow - exportStatus.LastBackup;
						var nextBackup = timeSinceLastBackup >= interval ? TimeSpan.Zero : interval - timeSinceLastBackup;
						incrementalBackupTimer = new Timer(state => TimerCallback(false), null, nextBackup, interval);
					}
					else
					{
						logger.Warn("Incremental periodic export interval is set to zero or less, incremental periodic export is now disabled");
					}

					if (exportConfigs.FullBackupIntervalMilliseconds.GetValueOrDefault() > 0)
					{
						var interval = TimeSpan.FromMilliseconds(exportConfigs.FullBackupIntervalMilliseconds.GetValueOrDefault());
						logger.Info("Full periodic export started, will export every" + interval.TotalMinutes + "minutes");

						var timeSinceLastBackup = SystemTime.UtcNow - exportStatus.LastFullBackup;
						var nextBackup = timeSinceLastBackup >= interval ? TimeSpan.Zero : interval - timeSinceLastBackup;
						fullBackupTimer = new Timer(state => TimerCallback(true), null, nextBackup, interval);
					}
					else
					{
						logger.Warn("Full periodic export interval is set to zero or less, full periodic export is now disabled");
					}


				}
				catch (Exception ex)
				{
					logger.ErrorException("Could not read periodic export config", ex);
					Database.AddAlert(new Alert
					{
						AlertLevel = AlertLevel.Error,
						CreatedAt = SystemTime.UtcNow,
						Message = ex.Message,
						Title = "Could not read periodic export config",
						Exception = ex.ToString(),
						UniqueKey = "Periodic Export Config Error"
					});
				}
			}
		}
Beispiel #2
0
        private void WaitForPeriodicExport(Func<string, JsonDocument> getDocument, PeriodicExportStatus previousStatus)
        {
            PeriodicExportStatus currentStatus = null;
            var done = SpinWait.SpinUntil(() =>
            {
                currentStatus = GetPerodicBackupStatus(getDocument);
                return currentStatus.LastDocsEtag != previousStatus.LastDocsEtag ||
                       currentStatus.LastAttachmentsEtag != previousStatus.LastAttachmentsEtag ||
                       currentStatus.LastDocsDeletionEtag != previousStatus.LastDocsDeletionEtag ||
                       currentStatus.LastAttachmentDeletionEtag != previousStatus.LastAttachmentDeletionEtag;
            }, Debugger.IsAttached ? TimeSpan.FromMinutes(120) : TimeSpan.FromMinutes(15));
            if (!done) throw new Exception("WaitForPeriodicExport failed");
            previousStatus.LastDocsEtag = currentStatus.LastDocsEtag;
            previousStatus.LastAttachmentsEtag = currentStatus.LastAttachmentsEtag;
            previousStatus.LastDocsDeletionEtag = currentStatus.LastDocsDeletionEtag;
            previousStatus.LastAttachmentDeletionEtag = currentStatus.LastAttachmentDeletionEtag;

        }
Beispiel #3
0
 protected void WaitForPeriodicExport(DocumentDatabase db, PeriodicExportStatus previousStatus)
 {
     WaitForPeriodicExport(key => db.Documents.Get(key, null), previousStatus);
 }
Beispiel #4
0
 protected void WaitForPeriodicExport(IDatabaseCommands commands, PeriodicExportStatus previousStatus)
 {
     WaitForPeriodicExport(commands.Get, previousStatus);
 }
Beispiel #5
0
        public void WaitForPeriodicExport(DocumentDatabase db, PeriodicExportStatus previousStatus, Func<PeriodicExportStatus, Etag> compareSelector)
        {
            PeriodicExportStatus currentStatus = null;
            var done = SpinWait.SpinUntil(() =>
            {
                currentStatus = GetPeriodicBackupStatus(db);
                return compareSelector(currentStatus) != compareSelector(previousStatus);
            }, Debugger.IsAttached ? TimeSpan.FromMinutes(120) : TimeSpan.FromMinutes(15));
            if (!done) throw new Exception("WaitForPeriodicExport failed");
            previousStatus.LastDocsEtag = currentStatus.LastDocsEtag;
            previousStatus.LastAttachmentsEtag = currentStatus.LastAttachmentsEtag;
            previousStatus.LastDocsDeletionEtag = currentStatus.LastDocsDeletionEtag;
            previousStatus.LastAttachmentDeletionEtag = currentStatus.LastAttachmentDeletionEtag;

        }