Exemplo n.º 1
0
        public void Execute()
        {
            VaultInventory vaultInventory = VaultInventoryParser.Parse(_vaultInventoryFile);

            NasFiles nasFiles = NasBackup.GetFiles(_nasPath);

            IEnumerable <GlacierFile> glacierFiles = vaultInventory.ArchiveList;

            IEnumerable <File> localFiles = nasFiles.Files;

            GlacierFile[] glacierExtraFiles = FileMatcher.GetGlacierExtraFiles(glacierFiles, localFiles)
                                              .ToArray();

            int glacierFilesCount = vaultInventory.ArchiveList.Count();

            int nasFilesCount = nasFiles.Files.Count();

            int glacierExtraFilesCount = glacierExtraFiles.Count();

            var result = new GlacierExtraResult(glacierFilesCount,
                                                nasFilesCount,
                                                glacierExtraFilesCount,
                                                glacierExtraFiles);

            ConsoleView.Show(result);
        }
        public void Execute()
        {
            VaultInventory vaultInventory = VaultInventoryParser.Parse(_vaultInventoryFile);

            NasFiles nasFiles = NasBackup.GetFiles(_nasPath);

            IEnumerable <GlacierFile> glacierFiles = vaultInventory.ArchiveList;

            IEnumerable <File> localFiles = nasFiles.Files;

            IEnumerable <GlacierFile> glacierExtraAgeFiles = FileMatcher.GetGlacierExtraFiles(glacierFiles,
                                                                                              localFiles,
                                                                                              _glacierOlderThan);

            var deleteFileResults = new List <GlacierDeleteFileResult>();

            using (var mgr = new ArchiveTransferManager(RegionEndpoint.USWest2))
            {
                foreach (GlacierFile g in glacierExtraAgeFiles)
                {
                    string deleteFailure = null;

                    bool isOldEnough = g.AgeDays > 90;

                    if (isOldEnough)
                    {
                        try
                        {
                            mgr.DeleteArchive(vaultName: "backup-home",
                                              archiveId: g.ArchiveId);
                        }
                        catch (Exception ex)
                        {
                            deleteFailure = ex.Message;
                        }
                    }
                    else
                    {
                        deleteFailure = string.Format("File is not old enough to be deleted. Age: [{0}]", g.AgeDays);
                    }

                    var deleteFileResult = new GlacierDeleteFileResult(g.NormalizedFilePath,
                                                                       deleteFailure,
                                                                       g.SizeBytes);

                    deleteFileResults.Add(deleteFileResult);
                }
            }

            var result = new DeleteGlacierFilesResult(deleteFileResults);

            ConsoleView.Show(result);
        }