Beispiel #1
0
        public void StartBackup(string backupDestinationDirectory, bool incrementalBackup, DatabaseDocument databaseDocument)
        {
            if (databaseDocument == null)
            {
                throw new ArgumentNullException("databaseDocument");
            }
            var document = Database.Documents.Get(BackupStatus.RavenBackupStatusDocumentKey);

            if (document != null)
            {
                var backupStatus = document.DataAsJson.JsonDeserialization <BackupStatus>();
                if (backupStatus.IsRunning)
                {
                    throw new InvalidOperationException("Backup is already running");
                }
            }

            if (incrementalBackup &&
                TransactionalStorage is Raven.Storage.Voron.TransactionalStorage &&
                Database.Configuration.Storage.AllowIncrementalBackups == false)
            {
                throw new InvalidOperationException($"In order to run incremental backups using Voron you must have the appropriate setting key ({RavenConfiguration.GetKey(x => x.Storage.AllowIncrementalBackups)}) set to true");
            }

            Database.Documents.Put(BackupStatus.RavenBackupStatusDocumentKey, null, RavenJObject.FromObject(new BackupStatus
            {
                Started   = SystemTime.UtcNow,
                IsRunning = true,
            }), new RavenJObject(), null);

            Database.IndexStorage.FlushMapIndexes();
            Database.IndexStorage.FlushReduceIndexes();

            TransactionalStorage.StartBackupOperation(Database, backupDestinationDirectory, incrementalBackup, databaseDocument);
        }
Beispiel #2
0
        public Task StartBackup(string backupDestinationDirectory, bool incrementalBackup, DatabaseDocument databaseDocument, ResourceBackupState state, CancellationToken token = default(CancellationToken))
        {
            if (databaseDocument == null)
            {
                throw new ArgumentNullException("databaseDocument");
            }
            var document = Database.Documents.Get(BackupStatus.RavenBackupStatusDocumentKey, null);

            if (document != null)
            {
                var backupStatus = document.DataAsJson.JsonDeserialization <BackupStatus>();
                if (backupStatus.IsRunning)
                {
                    throw new InvalidOperationException("Backup is already running");
                }
            }

            if (File.Exists(Path.Combine(backupDestinationDirectory, Constants.BackupFailureMarker)))
            {
                throw new InvalidOperationException("Backup failure marker was detected. In order to proceed remove old backup files or supply different backup directory.");
            }

            bool enableIncrementalBackup;

            if (incrementalBackup &&
                TransactionalStorage is Raven.Storage.Esent.TransactionalStorage &&
                (bool.TryParse(Database.Configuration.Settings[Constants.Esent.CircularLog], out enableIncrementalBackup) == false || enableIncrementalBackup))
            {
                throw new InvalidOperationException("In order to run incremental backups using Esent you must have circular logging disabled");
            }

            if (incrementalBackup &&
                TransactionalStorage is Raven.Storage.Voron.TransactionalStorage &&
                Database.Configuration.Storage.Voron.AllowIncrementalBackups == false)
            {
                throw new InvalidOperationException("In order to run incremental backups using Voron you must have the appropriate setting key (Raven/Voron/AllowIncrementalBackups) set to true");
            }

            Database.Documents.Put(BackupStatus.RavenBackupStatusDocumentKey, null, RavenJObject.FromObject(new BackupStatus
            {
                Started   = SystemTime.UtcNow,
                IsRunning = true,
            }), new RavenJObject(), null);

            Database.IndexStorage.FlushMapIndexes();
            Database.IndexStorage.FlushReduceIndexes();

            if (databaseDocument.Settings.ContainsKey("Raven/StorageTypeName") == false)
            {
                databaseDocument.Settings["Raven/StorageTypeName"] = TransactionalStorage.FriendlyName ?? TransactionalStorage.GetType().AssemblyQualifiedName;
            }

            var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(token, Database.WorkContext.CancellationToken);

            return(TransactionalStorage.StartBackupOperation(Database, backupDestinationDirectory, incrementalBackup, databaseDocument, state, linkedTokenSource.Token)
                   .ContinueWith(_ => linkedTokenSource.Dispose()));
        }
        public void StartBackup(string backupDestinationDirectory, bool incrementalBackup, DatabaseDocument databaseDocument)
        {
            if (databaseDocument == null)
            {
                throw new ArgumentNullException("databaseDocument");
            }
            var document = Database.Documents.Get(BackupStatus.RavenBackupStatusDocumentKey, null);

            if (document != null)
            {
                var backupStatus = document.DataAsJson.JsonDeserialization <BackupStatus>();
                if (backupStatus.IsRunning)
                {
                    throw new InvalidOperationException("Backup is already running");
                }
            }

            bool enableIncrementalBackup;

            if (incrementalBackup &&
                TransactionalStorage is Raven.Storage.Esent.TransactionalStorage &&
                (bool.TryParse(Database.Configuration.Settings["Raven/Esent/CircularLog"], out enableIncrementalBackup) == false || enableIncrementalBackup))
            {
                throw new InvalidOperationException("In order to run incremental backups using Esent you must have circular logging disabled");
            }

            if (incrementalBackup &&
                TransactionalStorage is Raven.Storage.Voron.TransactionalStorage &&
                Database.Configuration.Storage.Voron.AllowIncrementalBackups == false)
            {
                throw new InvalidOperationException("In order to run incremental backups using Voron you must have the appropriate setting key (Raven/Voron/AllowIncrementalBackups) set to true");
            }

            Database.Documents.Put(BackupStatus.RavenBackupStatusDocumentKey, null, RavenJObject.FromObject(new BackupStatus
            {
                Started   = SystemTime.UtcNow,
                IsRunning = true,
            }), new RavenJObject(), null);
            Database.IndexStorage.FlushMapIndexes();
            Database.IndexStorage.FlushReduceIndexes();

            if (databaseDocument.Settings.ContainsKey("Raven/StorageTypeName") == false)
            {
                databaseDocument.Settings["Raven/StorageTypeName"] = TransactionalStorage.FriendlyName ?? TransactionalStorage.GetType().AssemblyQualifiedName;
            }

            TransactionalStorage.StartBackupOperation(Database, backupDestinationDirectory, incrementalBackup, databaseDocument);
        }
Beispiel #4
0
        public void StartBackup(string backupDestinationDirectory)
        {
            var document = Get(BackupStatus.RavenBackupStatusDocumentKey, null);

            if (document != null)
            {
                var backupStatus = document.DataAsJson.JsonDeserialization <BackupStatus>();
                if (backupStatus.IsRunning)
                {
                    throw new InvalidOperationException("Backup is already running");
                }
            }
            Put(BackupStatus.RavenBackupStatusDocumentKey, null, JObject.FromObject(new BackupStatus
            {
                Started   = DateTime.UtcNow,
                IsRunning = true,
            }), new JObject(), null);
            IndexStorage.FlushAllIndexes();
            TransactionalStorage.StartBackupOperation(this, backupDestinationDirectory);
        }