// Prepare volume snapshots Dictionary <string, ShadowCopy> PrepareVolumes() { HashSet <string> vols = new HashSet <string>(); foreach (string p in _cfg.Sources) { vols.Add(Path.GetPathRoot(p)); } Dictionary <string, ShadowCopy> vss = new Dictionary <string, ShadowCopy>(vols.Count); foreach (string v in vols) { // FIXME: One VssBackup per volume should not be necessary (?) Console.WriteLine("Preparing volume " + v + "..."); ShadowCopy bkp = null; try { bkp = new ShadowCopy(); bkp.Setup(v); vss.Add(v, bkp); } catch (Exception e) { if (bkp != null) { bkp.PreBackup(); bkp.Dispose(false); bkp = null; } foreach (ShadowCopy b in vss.Values) { b.Dispose(false); } throw e; } } return(vss); }
public BackupEntry(string path, ShadowCopy vss) { _info = new FileInfo(path); _shadow = vss; }
// Lists all backup entries and applies filters void GetEntries() { _entries = new List <BackupEntry>(); Queue <string> dirQ = new Queue <string>(); foreach (string source in _cfg.Sources) { Console.WriteLine("Scanning source: " + source); string volRoot = Path.GetPathRoot(source); ShadowCopy vss = _shadows[volRoot]; string snapSource = vss.GetSnapshotPath(source); string rootPath = vss.GetSnapshotPath(String.Empty); if (Directory.Exists(snapSource)) { dirQ.Enqueue(snapSource); while (dirQ.Count > 0) { if (_cancel) { throw new BackupCanceledException(); } string path = dirQ.Dequeue(); try { // Subfolders string[] subdirs; if (_cfg.Flags["recursive"] && (subdirs = Directory.GetDirectories(path)).Length > 0) { foreach (string dir in subdirs) { BackupEntry entry = new BackupEntry(dir, vss); if (!entry.Info.IsSymbolicLink && !entry.Info.IsReparsePoint && !_filter.IsDirExcluded(entry)) { dirQ.Enqueue(dir); } entry.Dispose(); } } subdirs = null; // Files string[] files = Directory.GetFiles(path); if (files.Length > 0) { foreach (string f in files) { BackupEntry entry = new BackupEntry(f, vss); if (!entry.CanRead || _filter.IsFileExcluded(entry)) { entry.Dispose(); continue; } _entries.Add(entry); _size += entry.Info.FileSize / 1024; } } files = null; } catch (Exception e) { // TODO: More specific exception Console.WriteLine(e); Console.WriteLine(vss.GetRealPath(path) + " is not accessible."); } } } else if (File.Exists(snapSource)) { BackupEntry entry = new BackupEntry(snapSource, vss); if (_filter.IsFileExcluded(entry)) { continue; } _entries.Add(entry); _size += entry.Info.FileSize; } } GC.Collect(); }