public void Execute(object ignored) { try { src = src.ToFullPath(); to = to.ToFullPath(); var backupConfigPath = Path.Combine(to, "RavenDB.Backup"); if (Directory.Exists(to) && File.Exists(backupConfigPath)) // trying to backup to an existing backup folder { if (!incrementalBackup) throw new InvalidOperationException("Denying request to perform a full backup to an existing backup folder. Try doing an incremental backup instead."); var incrementalTag = DateTime.UtcNow.ToString("Inc yyyy-MM-dd hh-mm-ss"); to = Path.Combine(to, incrementalTag); } else { incrementalBackup = false; // destination wasn't detected as a backup folder, automatically revert to a full backup if incremental was specified } log.Info("Starting backup of '{0}' to '{1}'", src, to); var directoryBackups = new List<DirectoryBackup> { new DirectoryBackup(Path.Combine(src, "IndexDefinitions"), Path.Combine(to, "IndexDefinitions"), Path.Combine(src, "Temp" + Guid.NewGuid().ToString("N")), incrementalBackup) }; directoryBackups.AddRange(from index in Directory.GetDirectories(database.Configuration.IndexStoragePath) let fromIndex = Path.Combine(database.Configuration.IndexStoragePath, Path.GetFileName(index)) let toIndex = Path.Combine(to, "Indexes", Path.GetFileName(index)) let tempIndex = Path.Combine(src, Path.Combine("BackupTempDirectories",Guid.NewGuid().ToString("N"))) select new DirectoryBackup(fromIndex, toIndex, tempIndex, incrementalBackup)); foreach (var directoryBackup in directoryBackups) { directoryBackup.Notify += UpdateBackupStatus; directoryBackup.Prepare(); } foreach (var directoryBackup in directoryBackups) { directoryBackup.Execute(); } var esentBackup = new EsentBackup(instance, to, incrementalBackup ? BackupGrbit.Incremental : BackupGrbit.Atomic); esentBackup.Notify += UpdateBackupStatus; esentBackup.Execute(); File.WriteAllText(backupConfigPath, "Backup completed " + DateTime.Now); } catch (Exception e) { log.ErrorException("Failed to complete backup", e); UpdateBackupStatus("Failed to complete backup because: " + e.Message, BackupStatus.BackupMessageSeverity.Error); } finally { CompleteBackup(); } }
protected override void ExecuteBackup(string backupPath, bool isIncrementalBackup) { if (string.IsNullOrWhiteSpace(backupPath)) throw new ArgumentNullException("backupPath"); // It doesn't seem to be possible to get the % complete from an esent backup, but any status msgs // that is does give us are displayed live during the backup. var esentBackup = new EsentBackup(instance, backupPath, isIncrementalBackup ? BackupGrbit.Incremental : BackupGrbit.Atomic); esentBackup.Notify += UpdateBackupStatus; esentBackup.Execute(); }
public void Execute(object ignored) { try { to = to.ToFullPath(); src = src.ToFullPath(); log.Info("Starting backup of '{0}' to '{1}'", src, to); var directoryBackups = new List <DirectoryBackup> { new DirectoryBackup(Path.Combine(src, "IndexDefinitions"), Path.Combine(to, "IndexDefinitions"), Path.Combine(src, "Temp" + Guid.NewGuid().ToString("N"))) }; directoryBackups.AddRange(from index in Directory.GetDirectories(database.Configuration.IndexStoragePath) let fromIndex = Path.Combine(database.Configuration.IndexStoragePath, Path.GetFileName(index)) let toIndex = Path.Combine(to, "Indexes", Path.GetFileName(index)) let tempIndex = Path.Combine(src, Path.Combine("BackupTempDirectories", Guid.NewGuid().ToString("N"))) select new DirectoryBackup(fromIndex, toIndex, tempIndex)); foreach (var directoryBackup in directoryBackups) { directoryBackup.Notify += UpdateBackupStatus; directoryBackup.Prepare(); } foreach (var directoryBackup in directoryBackups) { directoryBackup.Execute(); } var esentBackup = new EsentBackup(instance, to); esentBackup.Notify += UpdateBackupStatus; esentBackup.Execute(); } catch (Exception e) { log.ErrorException("Failed to complete backup", e); UpdateBackupStatus("Failed to complete backup because: " + e.Message, BackupStatus.BackupMessageSeverity.Error); } finally { CompleteBackup(); } }
public void Execute(object ignored) { try { to = to.ToFullPath(); src = src.ToFullPath(); log.Info("Starting backup of '{0}' to '{1}'", src, to); var directoryBackups = new List<DirectoryBackup> { new DirectoryBackup(Path.Combine(src, "IndexDefinitions"), Path.Combine(to, "IndexDefinitions"), Path.Combine(src, "Temp" + Guid.NewGuid().ToString("N"))) }; directoryBackups.AddRange(from index in Directory.GetDirectories(database.Configuration.IndexStoragePath) let fromIndex = Path.Combine(database.Configuration.IndexStoragePath, Path.GetFileName(index)) let toIndex = Path.Combine(to, "Indexes", Path.GetFileName(index)) let tempIndex = Path.Combine(src, Path.Combine("BackupTempDirectories",Guid.NewGuid().ToString("N"))) select new DirectoryBackup(fromIndex, toIndex, tempIndex)); foreach (var directoryBackup in directoryBackups) { directoryBackup.Notify += UpdateBackupStatus; directoryBackup.Prepare(); } foreach (var directoryBackup in directoryBackups) { directoryBackup.Execute(); } var esentBackup = new EsentBackup(instance, to, incrementalBackup ? BackupGrbit.Incremental : BackupGrbit.Atomic); esentBackup.Notify+=UpdateBackupStatus; esentBackup.Execute(); } catch (Exception e) { log.ErrorException("Failed to complete backup", e); UpdateBackupStatus("Failed to complete backup because: " + e.Message, BackupStatus.BackupMessageSeverity.Error); } finally { CompleteBackup(); } }
public void Execute(object ignored) { try { log.InfoFormat("Starting backup of '{0}' to '{1}'", src, to); var directoryBackups = new List<DirectoryBackup> { new DirectoryBackup(Path.Combine(src, "IndexDefinitions"), Path.Combine(to, "IndexDefinitions"), Path.Combine(src, "Temp" + Guid.NewGuid().ToString("N"))) }; directoryBackups.AddRange(from index in Directory.GetDirectories(Path.Combine(src, "Indexes")) let fromIndex = Path.Combine(src, "Indexes", Path.GetFileName(index)) let toIndex = Path.Combine(to, "Indexes", Path.GetFileName(index)) let tempIndex = Path.Combine(src, Path.Combine("BackupTempDirectories",Guid.NewGuid().ToString("N"))) select new DirectoryBackup(fromIndex, toIndex, tempIndex)); foreach (var directoryBackup in directoryBackups) { directoryBackup.Notify += UpdateBackupStatus; directoryBackup.Prepare(); } foreach (var directoryBackup in directoryBackups) { directoryBackup.Execute(); } var esentBackup = new EsentBackup(instance, to); esentBackup.Notify+=UpdateBackupStatus; esentBackup.Execute(); } catch (Exception e) { log.Error("Failed to complete backup", e); UpdateBackupStatus("Failed to complete backup because: " + e.Message); } finally { CompleteBackup(); } }
public void Execute(object ignored) { try { src = src.ToFullPath(); to = to.ToFullPath(); var backupConfigPath = Path.Combine(to, "RavenDB.Backup"); if (Directory.Exists(to) && File.Exists(backupConfigPath)) // trying to backup to an existing backup folder { if (!incrementalBackup) { throw new InvalidOperationException("Denying request to perform a full backup to an existing backup folder. Try doing an incremental backup instead."); } var incrementalTag = SystemTime.UtcNow.ToString("Inc yyyy-MM-dd hh-mm-ss"); to = Path.Combine(to, incrementalTag); } else { incrementalBackup = false; // destination wasn't detected as a backup folder, automatically revert to a full backup if incremental was specified } log.Info("Starting backup of '{0}' to '{1}'", src, to); var directoryBackups = new List <DirectoryBackup> { new DirectoryBackup(Path.Combine(src, "IndexDefinitions"), Path.Combine(to, "IndexDefinitions"), Path.Combine(src, "Temp" + Guid.NewGuid().ToString("N")), incrementalBackup) }; directoryBackups.AddRange(from index in Directory.GetDirectories(database.Configuration.IndexStoragePath) let fromIndex = Path.Combine(database.Configuration.IndexStoragePath, Path.GetFileName(index)) let toIndex = Path.Combine(to, "Indexes", Path.GetFileName(index)) let tempIndex = Path.Combine(src, Path.Combine("BackupTempDirectories", Guid.NewGuid().ToString("N"))) select new DirectoryBackup(fromIndex, toIndex, tempIndex, incrementalBackup)); foreach (var directoryBackup in directoryBackups) { directoryBackup.Notify += UpdateBackupStatus; directoryBackup.Prepare(); } foreach (var directoryBackup in directoryBackups) { directoryBackup.Execute(); } // Make sure we have an Indexes folder in the backup location if (!Directory.Exists(Path.Combine(to, "Indexes"))) { Directory.CreateDirectory(Path.Combine(to, "Indexes")); } var esentBackup = new EsentBackup(instance, to, incrementalBackup ? BackupGrbit.Incremental : BackupGrbit.Atomic); esentBackup.Notify += UpdateBackupStatus; esentBackup.Execute(); File.WriteAllText(backupConfigPath, "Backup completed " + SystemTime.UtcNow); } catch (Exception e) { log.ErrorException("Failed to complete backup", e); UpdateBackupStatus("Failed to complete backup because: " + e.Message, BackupStatus.BackupMessageSeverity.Error); } finally { CompleteBackup(); } }
public void Execute(object ignored) { try { src = src.ToFullPath(); to = to.ToFullPath(); string basePath = to; string incrementalTag = null; var backupConfigPath = Path.Combine(to, "RavenDB.Backup"); if (Directory.Exists(to) && File.Exists(backupConfigPath)) // trying to backup to an existing backup folder { if (!incrementalBackup) throw new InvalidOperationException("Denying request to perform a full backup to an existing backup folder. Try doing an incremental backup instead."); incrementalTag = SystemTime.UtcNow.ToString("Inc yyyy-MM-dd hh-mm-ss"); to = Path.Combine(to, incrementalTag); } else { incrementalBackup = false; // destination wasn't detected as a backup folder, automatically revert to a full backup if incremental was specified } log.Info("Starting backup of '{0}' to '{1}'", src, to); var directoryBackups = new List<DirectoryBackup> { new DirectoryBackup(Path.Combine(src, "IndexDefinitions"), Path.Combine(to, "IndexDefinitions"), Path.Combine(src, "Temp" + Guid.NewGuid().ToString("N")), incrementalBackup) }; database.IndexStorage.Backup(basePath, incrementalTag); foreach (var directoryBackup in directoryBackups) { directoryBackup.Notify += UpdateBackupStatus; directoryBackup.Prepare(); } foreach (var directoryBackup in directoryBackups) { directoryBackup.Execute(); } // Make sure we have an Indexes folder in the backup location if (!Directory.Exists(Path.Combine(to, "Indexes"))) Directory.CreateDirectory(Path.Combine(to, "Indexes")); var esentBackup = new EsentBackup(instance, to, incrementalBackup ? BackupGrbit.Incremental : BackupGrbit.Atomic); esentBackup.Notify += UpdateBackupStatus; esentBackup.Execute(); if(databaseDocument != null) File.WriteAllText(Path.Combine(to, "Database.Document"), RavenJObject.FromObject(databaseDocument).ToString()); File.WriteAllText(backupConfigPath, "Backup completed " + SystemTime.UtcNow); } catch (AggregateException e) { var ne = e.ExtractSingleInnerException(); log.ErrorException("Failed to complete backup", ne); UpdateBackupStatus("Failed to complete backup because: " + ne.Message, BackupStatus.BackupMessageSeverity.Error); } catch (Exception e) { log.ErrorException("Failed to complete backup", e); UpdateBackupStatus("Failed to complete backup because: " + e.Message, BackupStatus.BackupMessageSeverity.Error); } finally { CompleteBackup(); } }
public void Execute() { try { src = src.ToFullPath(); to = to.ToFullPath(); string basePath = to; string incrementalTag = null; var backupConfigPath = Path.Combine(to, "RavenDB.Backup"); if (Directory.Exists(to) && File.Exists(backupConfigPath)) // trying to backup to an existing backup folder { if (!incrementalBackup) { throw new InvalidOperationException("Denying request to perform a full backup to an existing backup folder. Try doing an incremental backup instead."); } incrementalTag = SystemTime.UtcNow.ToString("'Inc' yyyy-MM-dd HH-mm-ss", CultureInfo.InvariantCulture); to = Path.Combine(to, incrementalTag); } else { incrementalBackup = false; // destination wasn't detected as a backup folder, automatically revert to a full backup if incremental was specified } log.Info("Starting backup of '{0}' to '{1}'", src, to); var directoryBackups = new List <DirectoryBackup> { new DirectoryBackup(Path.Combine(src, "IndexDefinitions"), Path.Combine(to, "IndexDefinitions"), Path.Combine(src, "Temp" + Guid.NewGuid().ToString("N")), incrementalBackup) }; database.IndexStorage.Backup(basePath, incrementalTag); foreach (var directoryBackup in directoryBackups) { directoryBackup.Notify += UpdateBackupStatus; directoryBackup.Prepare(); } foreach (var directoryBackup in directoryBackups) { directoryBackup.Execute(); } // Make sure we have an Indexes folder in the backup location if (!Directory.Exists(Path.Combine(to, "Indexes"))) { Directory.CreateDirectory(Path.Combine(to, "Indexes")); } var esentBackup = new EsentBackup(instance, to, incrementalBackup ? BackupGrbit.Incremental : BackupGrbit.Atomic); esentBackup.Notify += UpdateBackupStatus; esentBackup.Execute(); if (databaseDocument != null) { File.WriteAllText(Path.Combine(to, "Database.Document"), RavenJObject.FromObject(databaseDocument).ToString()); } File.WriteAllText(backupConfigPath, "Backup completed " + SystemTime.UtcNow); } catch (AggregateException e) { var ne = e.ExtractSingleInnerException(); log.ErrorException("Failed to complete backup", ne); UpdateBackupStatus("Failed to complete backup because: " + ne.Message, BackupStatus.BackupMessageSeverity.Error); } catch (Exception e) { log.ErrorException("Failed to complete backup", e); UpdateBackupStatus("Failed to complete backup because: " + e.Message, BackupStatus.BackupMessageSeverity.Error); } finally { CompleteBackup(); } }