override public bool IsFileExcluded(BackupEntry entry) { // Exclude if archive attribute is not set (or entry is filtered) // Log if ((entry.Info.Attributes & FileAttributes.Archive) == FileAttributes.None) { Console.WriteLine( "File excluded: " + entry.RealPath ); return(true); } else { return(base.IsFileExcluded(entry)); } }
override public void Write(BackupEntry entry) { base.Write(); Console.WriteLine("Compressing: " + entry.RealPath); ZipEntry ez; string entryPath = Path.GetPathRoot(entry.RealPath).Remove(1) + "/"; if (entry.Info.IsDirectory) { entryPath += _zipFactory.NameTransform.TransformDirectory(entry.RealPath); ez = _zipFactory.MakeDirectoryEntry(entryPath, false); } else if (entry.Info.IsFile) { // Windows specific metadata (timestamps) NTTaggedData meta = new NTTaggedData(); meta.CreateTime = entry.Info.Created; meta.LastModificationTime = entry.Info.LastModified; meta.LastAccessTime = entry.Info.LastAccessed; entryPath += _zipFactory.NameTransform.TransformFile(entry.RealPath); ez = _zipFactory.MakeFileEntry(entryPath, false); ez.DateTime = entry.Info.LastModified; ez.ExtraData = meta.GetData(); } else { return; } _zip.PutNextEntry(ez); if (entry.Info.IsFile) { using (Stream fs = entry.Stream) { int sourceBytes; do { sourceBytes = fs.Read(_buffer, 0, _buffer.Length); _zip.Write(_buffer, 0, sourceBytes); } while (sourceBytes > 0); } } }
override public bool IsFileExcluded(BackupEntry entry) { bool exclude = Config.Exclude.Any( x => { if (x.StartsWith("r/") && x.EndsWith("/")) { // Regex return(Regex.IsMatch(entry.RealPath, x.Substring(2, x.Length - 3))); } else if (x.StartsWith("x/") && x.EndsWith("/")) { // File extension(s) return(x.Substring(2, x.Length - 3).Split(';') .Any( y => { return (y.Length > 0 && entry.RealPath.EndsWith("." + y, StringComparison.OrdinalIgnoreCase)) || (y.StartsWith(".") && entry.RealPath.EndsWith(y, StringComparison.OrdinalIgnoreCase)); } )); } else { // Basic path return(entry.RealPath.StartsWith(x)); } } ); // Log if (exclude) { Console.WriteLine( "File excluded: " + entry.RealPath ); } return(exclude); }
public abstract void OnWrite(BackupEntry entry);
override public bool IsDirExcluded(BackupEntry entry) { return(false); }
public abstract bool IsFileExcluded(BackupEntry entry);
public abstract bool IsDirExcluded(BackupEntry entry);
public override void OnWrite(BackupEntry entry) { }
public virtual void Write(BackupEntry entry) { Write(); }
// 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(); }