@@ -28,6 +28,7 @@ private class HostEntry
2828 public string Host { get ; set ; }
2929 public string Name { get ; set ; }
3030 public bool IsWindows { get ; set ; }
31+ public Regex IgnoreRegex { get ; set ; }
3132
3233 public override string ToString ( )
3334 {
@@ -320,7 +321,7 @@ private static long BackupFile(string root, string remotePath, SftpClient client
320321 return 0 ;
321322 }
322323
323- private static long BackupFolder ( string root , string path , SftpClient client )
324+ private static long BackupFolder ( HostEntry host , string root , string path , SftpClient client )
324325 {
325326 long size = 0 ;
326327 foreach ( string fileOrFolder in path . Split ( '|' ) . Select ( s => s . Trim ( ) ) . Where ( s => s . Length != 0 ) )
@@ -341,13 +342,13 @@ private static long BackupFolder(string root, string path, SftpClient client)
341342 else
342343 {
343344 SftpFile [ ] files = client . ListDirectory ( fileOrFolder ) . Where ( f => f . IsRegularFile || ( f . IsDirectory && ! f . Name . StartsWith ( "." ) ) ) . ToArray ( ) ;
344- Parallel . ForEach ( files . Where ( f => f . IsRegularFile ) , parallelOptions , ( _file ) =>
345+ Parallel . ForEach ( files . Where ( f => f . IsRegularFile && ( host . IgnoreRegex == null || ! host . IgnoreRegex . IsMatch ( f . FullName ) ) ) , parallelOptions , ( _file ) =>
345346 {
346347 Interlocked . Add ( ref size , BackupFile ( root , _file . FullName , client ) ) ;
347348 } ) ;
348349 Parallel . ForEach ( files . Where ( f => f . IsDirectory ) , parallelOptions2 , ( folder ) =>
349350 {
350- Interlocked . Add ( ref size , BackupFolder ( root , folder . FullName , client ) ) ;
351+ Interlocked . Add ( ref size , BackupFolder ( host , root , folder . FullName , client ) ) ;
351352 } ) ;
352353 }
353354 }
@@ -400,7 +401,11 @@ private static void ClientLoop(string root, HostEntry host, List<string> command
400401 {
401402 if ( command . StartsWith ( "$backup " , StringComparison . OrdinalIgnoreCase ) )
402403 {
403- backupSize += BackupFolder ( backupPath , command . Substring ( 8 ) , sftpClient ) ;
404+ backupSize += BackupFolder ( host , backupPath , command . Substring ( 8 ) , sftpClient ) ;
405+ }
406+ else if ( command . StartsWith ( "$ignore " , StringComparison . OrdinalIgnoreCase ) )
407+ {
408+ host . IgnoreRegex = new Regex ( command . Substring ( 8 ) , RegexOptions . IgnoreCase | RegexOptions . CultureInvariant ) ;
404409 }
405410 }
406411 else
0 commit comments