Esempio n. 1
0
        public void Execute(object ignored)
        {
            try
            {
                to  = to.ToFullPath();
                src = src.ToFullPath();
                logger.Info("Starting backup of '{0}' to '{1}'", src, to);
                var directoryBackups = new List <DirectoryBackup>
                {
                    new DirectoryBackup(src, to, Path.Combine("TempData" + Guid.NewGuid().ToString("N")), false),
                    new DirectoryBackup(Path.Combine(src, "IndexDefinitions"), Path.Combine(to, "IndexDefinitions"),
                                        Path.Combine(src, "Temp" + Guid.NewGuid().ToString("N")), false)
                };
                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, false));


                persistentSource.Read(log =>
                {
                    persistentSource.FlushLog();

                    foreach (var directoryBackup in directoryBackups)
                    {
                        directoryBackup.Notify += UpdateBackupStatus;
                        directoryBackup.Prepare();
                    }

                    foreach (var directoryBackup in directoryBackups)
                    {
                        directoryBackup.Execute();
                    }

                    return(0);                   // ignored
                });
            }
            catch (Exception e)
            {
                logger.ErrorException("Failed to complete backup", e);
                UpdateBackupStatus("Failed to complete backup because: " + e.Message, BackupStatus.BackupMessageSeverity.Error);
            }
            finally
            {
                CompleteBackup();
            }
        }
Esempio n. 2
0
        private void Commit(Guid txId)
        {
            // this assume that munin transactions always use a single thread

            var cmds = new List <Command>();

            foreach (var table in tables)
            {
                var commandsToCommit = table.GetCommandsToCommit(txId);
                if (commandsToCommit == null)
                {
                    continue;
                }
                cmds.AddRange(commandsToCommit);
            }

            if (cmds.Count == 0)
            {
                return;
            }

            persistentSource.Write(log =>
            {
                log.Position = log.Length;                 // always write at the end of the file

                for (int i = 0; i < cmds.Count; i += 1024)
                {
                    WriteCommands(cmds.Skip(i).Take(1024), log);
                }
                persistentSource.FlushLog();                 // flush all the index changes to disk

                foreach (var table in tables)
                {
                    table.CompleteCommit(txId);
                }

                foreach (var command in cmds)
                {
                    if (command.Payload != null)
                    {
                        command.Payload.Dispose();
                    }
                }
            });
        }
Esempio n. 3
0
        public void Execute()
        {
            try
            {
                to  = to.ToFullPath();
                src = src.ToFullPath();
                logger.Info("Starting backup of '{0}' to '{1}'", src, to);
                var directoryBackups = new List <DirectoryBackup>
                {
                    new DirectoryBackup(src, to, Path.Combine("TempData" + Guid.NewGuid().ToString("N")), false),
                    new DirectoryBackup(Path.Combine(src, "IndexDefinitions"), Path.Combine(to, "IndexDefinitions"),
                                        Path.Combine(src, "Temp" + Guid.NewGuid().ToString("N")), false)
                };

                database.IndexStorage.Backup(to);

                persistentSource.Read(log =>
                {
                    persistentSource.FlushLog();

                    foreach (var directoryBackup in directoryBackups)
                    {
                        directoryBackup.Notify += UpdateBackupStatus;
                        directoryBackup.Prepare();
                    }

                    foreach (var directoryBackup in directoryBackups)
                    {
                        directoryBackup.Execute();
                    }

                    return(0);                   // ignored
                });
            }
            catch (Exception e)
            {
                logger.ErrorException("Failed to complete backup", e);
                UpdateBackupStatus("Failed to complete backup because: " + e.Message, BackupStatus.BackupMessageSeverity.Error);
            }
            finally
            {
                CompleteBackup();
            }
        }