示例#1
0
        public void DoRun(Database.LocalDeleteDatabase db, ref System.Data.IDbTransaction transaction, bool hasVerifiedBacked, bool forceCompact, BackendManager sharedManager)
        {
            // Workaround where we allow a running backendmanager to be used
            using (var bk = sharedManager == null ? new BackendManager(m_backendurl, m_options, m_result.BackendWriter, db) : null)
            {
                var backend = bk ?? sharedManager;

                if (!hasVerifiedBacked && !m_options.NoBackendverification)
                {
                    FilelistProcessor.VerifyRemoteList(backend, m_options, db, m_result.BackendWriter);
                }

                IListResultFileset[]      filesets         = db.FilesetsWithBackupVersion.ToArray();
                List <IListResultFileset> versionsToDelete = new List <IListResultFileset>();
                versionsToDelete.AddRange(new SpecificVersionsRemover(this.m_options).GetFilesetsToDelete(filesets));
                versionsToDelete.AddRange(new KeepTimeRemover(this.m_options).GetFilesetsToDelete(filesets));
                versionsToDelete.AddRange(new RetentionPolicyRemover(this.m_options).GetFilesetsToDelete(filesets));

                // When determining the number of full versions to keep, we need to ignore the versions already marked for removal.
                versionsToDelete.AddRange(new KeepVersionsRemover(this.m_options).GetFilesetsToDelete(filesets.Except(versionsToDelete)));

                if (!m_options.AllowFullRemoval && filesets.Length == versionsToDelete.Count)
                {
                    Logging.Log.WriteInformationMessage(LOGTAG, "PreventingLastFilesetRemoval", "Preventing removal of last fileset, use --{0} to allow removal ...", "allow-full-removal");
                    versionsToDelete = versionsToDelete.OrderBy(x => x.Version).Skip(1).ToList();
                }

                if (versionsToDelete.Count > 0)
                {
                    Logging.Log.WriteInformationMessage(LOGTAG, "DeleteRemoteFileset", "Deleting {0} remote fileset(s) ...", versionsToDelete.Count);
                }

                var lst = db.DropFilesetsFromTable(versionsToDelete.Select(x => x.Time).ToArray(), transaction).ToArray();
                foreach (var f in lst)
                {
                    db.UpdateRemoteVolume(f.Key, RemoteVolumeState.Deleting, f.Value, null, transaction);
                }

                if (!m_options.Dryrun)
                {
                    transaction.Commit();
                    transaction = db.BeginTransaction();
                }

                foreach (var f in lst)
                {
                    if (m_result.TaskControlRendevouz() == TaskControlState.Stop)
                    {
                        backend.WaitForComplete(db, transaction);
                        return;
                    }

                    if (!m_options.Dryrun)
                    {
                        backend.Delete(f.Key, f.Value);
                    }
                    else
                    {
                        Logging.Log.WriteDryrunMessage(LOGTAG, "WouldDeleteRemoteFileset", "Would delete remote fileset: {0}", f.Key);
                    }
                }

                if (sharedManager == null)
                {
                    backend.WaitForComplete(db, transaction);
                }
                else
                {
                    backend.WaitForEmpty(db, transaction);
                }

                var count = lst.Length;
                if (!m_options.Dryrun)
                {
                    if (count == 0)
                    {
                        Logging.Log.WriteInformationMessage(LOGTAG, "DeleteResults", "No remote filesets were deleted");
                    }
                    else
                    {
                        Logging.Log.WriteInformationMessage(LOGTAG, "DeleteResults", "Deleted {0} remote fileset(s)", count);
                    }
                }
                else
                {
                    if (count == 0)
                    {
                        Logging.Log.WriteDryrunMessage(LOGTAG, "WouldDeleteResults", "No remote filesets would be deleted");
                    }
                    else
                    {
                        Logging.Log.WriteDryrunMessage(LOGTAG, "WouldDeleteResults", "{0} remote fileset(s) would be deleted", count);
                    }

                    if (count > 0 && m_options.Dryrun)
                    {
                        Logging.Log.WriteDryrunMessage(LOGTAG, "WouldDeleteHelp", "Remove --dry-run to actually delete files");
                    }
                }

                if (!m_options.NoAutoCompact && (forceCompact || versionsToDelete.Count > 0))
                {
                    m_result.CompactResults = new CompactResults(m_result);
                    new CompactHandler(m_backendurl, m_options, (CompactResults)m_result.CompactResults).DoCompact(db, true, ref transaction, sharedManager);
                }

                m_result.SetResults(versionsToDelete.Select(v => new Tuple <long, DateTime>(v.Version, v.Time)), m_options.Dryrun);
            }
        }
示例#2
0
        public void DoRun(Database.LocalDeleteDatabase db, System.Data.IDbTransaction transaction, bool hasVerifiedBacked, bool forceCompact)
        {
            using (var backend = new BackendManager(m_backendurl, m_options, m_result.BackendWriter, db))
            {
                if (!hasVerifiedBacked && !m_options.NoBackendverification)
                {
                    FilelistProcessor.VerifyRemoteList(backend, m_options, db, m_result.BackendWriter);
                }

                var filesetNumbers = db.FilesetTimes.Zip(Enumerable.Range(0, db.FilesetTimes.Count()), (a, b) => new Tuple <long, DateTime>(b, a.Value));
                var toDelete       = m_options.GetFilesetsToDelete(db.FilesetTimes.Select(x => x.Value).ToArray());

                if (toDelete != null && toDelete.Length > 0)
                {
                    m_result.AddMessage(string.Format("Deleting {0} remote fileset(s) ...", toDelete.Length));
                }

                var count = 0L;
                foreach (var f in db.DropFilesetsFromTable(toDelete, transaction))
                {
                    if (m_result.TaskControlRendevouz() == TaskControlState.Stop)
                    {
                        backend.WaitForComplete(db, transaction);
                        return;
                    }

                    count++;
                    if (!m_options.Dryrun)
                    {
                        backend.Delete(f.Key, f.Value);
                    }
                    else
                    {
                        m_result.AddDryrunMessage(string.Format("Would delete remote fileset: {0}", f.Key));
                    }
                }

                backend.WaitForComplete(db, transaction);

                if (!m_options.Dryrun)
                {
                    if (count == 0)
                    {
                        m_result.AddMessage("No remote filesets were deleted");
                    }
                    else
                    {
                        m_result.AddMessage(string.Format("Deleted {0} remote fileset(s)", count));
                    }
                }
                else
                {
                    if (count == 0)
                    {
                        m_result.AddDryrunMessage("No remote filesets would be deleted");
                    }
                    else
                    {
                        m_result.AddDryrunMessage(string.Format("{0} remote fileset(s) would be deleted", count));
                    }

                    if (count > 0 && m_options.Dryrun)
                    {
                        m_result.AddDryrunMessage("Remove --dry-run to actually delete files");
                    }
                }

                if (!m_options.NoAutoCompact && (forceCompact || (toDelete != null && toDelete.Length > 0)))
                {
                    m_result.CompactResults = new CompactResults(m_result);
                    new CompactHandler(m_backendurl, m_options, (CompactResults)m_result.CompactResults).DoCompact(db, true, transaction);
                }

                m_result.SetResults(
                    from n in filesetNumbers
                    where toDelete.Contains(n.Item2)
                    select n,
                    m_options.Dryrun);
            }
        }
示例#3
0
        public void DoRun(Database.LocalDeleteDatabase db, ref System.Data.IDbTransaction transaction, bool hasVerifiedBacked, bool forceCompact, BackendManager sharedManager)
        {
            // Workaround where we allow a running backendmanager to be used
            using (var bk = sharedManager == null ? new BackendManager(m_backendurl, m_options, m_result.BackendWriter, db) : null)
            {
                var backend = bk ?? sharedManager;

                if (!hasVerifiedBacked && !m_options.NoBackendverification)
                {
                    FilelistProcessor.VerifyRemoteList(backend, m_options, db, m_result.BackendWriter);
                }

                var filesetNumbers = db.FilesetTimes.Zip(Enumerable.Range(0, db.FilesetTimes.Count()), (a, b) => new Tuple <long, DateTime>(b, a.Value)).ToList();
                var sets           = db.FilesetTimes.Select(x => x.Value).ToArray();
                var toDelete       = GetFilesetsToDelete(sets);

                if (!m_options.AllowFullRemoval && sets.Length == toDelete.Length)
                {
                    m_result.AddMessage(string.Format("Preventing removal of last fileset, use --{0} to allow removal ...", "allow-full-removal"));
                    toDelete = toDelete.Skip(1).ToArray();
                }

                if (toDelete != null && toDelete.Length > 0)
                {
                    m_result.AddMessage(string.Format("Deleting {0} remote fileset(s) ...", toDelete.Length));
                }

                var lst = db.DropFilesetsFromTable(toDelete, transaction).ToArray();
                foreach (var f in lst)
                {
                    db.UpdateRemoteVolume(f.Key, RemoteVolumeState.Deleting, f.Value, null, transaction);
                }

                if (!m_options.Dryrun)
                {
                    transaction.Commit();
                    transaction = db.BeginTransaction();
                }

                foreach (var f in lst)
                {
                    if (m_result.TaskControlRendevouz() == TaskControlState.Stop)
                    {
                        backend.WaitForComplete(db, transaction);
                        return;
                    }

                    if (!m_options.Dryrun)
                    {
                        backend.Delete(f.Key, f.Value);
                    }
                    else
                    {
                        m_result.AddDryrunMessage(string.Format("Would delete remote fileset: {0}", f.Key));
                    }
                }

                if (sharedManager == null)
                {
                    backend.WaitForComplete(db, transaction);
                }
                else
                {
                    backend.WaitForEmpty(db, transaction);
                }

                var count = lst.Length;
                if (!m_options.Dryrun)
                {
                    if (count == 0)
                    {
                        m_result.AddMessage("No remote filesets were deleted");
                    }
                    else
                    {
                        m_result.AddMessage(string.Format("Deleted {0} remote fileset(s)", count));
                    }
                }
                else
                {
                    if (count == 0)
                    {
                        m_result.AddDryrunMessage("No remote filesets would be deleted");
                    }
                    else
                    {
                        m_result.AddDryrunMessage(string.Format("{0} remote fileset(s) would be deleted", count));
                    }

                    if (count > 0 && m_options.Dryrun)
                    {
                        m_result.AddDryrunMessage("Remove --dry-run to actually delete files");
                    }
                }

                if (!m_options.NoAutoCompact && (forceCompact || (toDelete != null && toDelete.Length > 0)))
                {
                    m_result.CompactResults = new CompactResults(m_result);
                    new CompactHandler(m_backendurl, m_options, (CompactResults)m_result.CompactResults).DoCompact(db, true, ref transaction, sharedManager);
                }

                m_result.SetResults(
                    from n in filesetNumbers
                    where toDelete.Contains(n.Item2)
                    select n,
                    m_options.Dryrun);
            }
        }