Filter rule for --remove-sent-files?
Matt McCutchen
hashproduct+rsync at gmail.com
Fri Aug 10 15:34:09 GMT 2007
On 8/8/07, Akshay Kulkarni <akshayk_iitb at yahoo.co.in> wrote:
> I want to transfer a bunch of files, and then delete only those files
> from the source that match a certain pattern. It would be nice to have a
> filter rule to specify include and exclude patterns for the
> --remove-sent-files option. As far as I know, currently there is no such
> rule. The way I'm doing it is, I first transfer those files which I
> don't want to delete from the source after transfer, and then, using
> --remove-sent-files, transfer those that I want to delete. This requires
> running rsync twice.
Yes, it might be nice to have filter rules for --remove-sent-files,
but to me it seems to be a minor case. Running rsync twice is a
decent solution. Another option is to have rsync log the files it
transfers and have another program read the output and delete
whichever of the files ought to be deleted. For example, you could
run:
rsync -r src/ dest/ -vv --out-format='xfer %b %n' | ./my-remove-sent-files
Where ./my-remove-sent-files is this Perl script:
#!/usr/bin/env perl
while (<STDIN>) {
print;
chomp;
if (/^(.*) is uptodate$/ or /^xfer \d+ (.*)$/) {
my $f = $1;
# Substitute your pattern(s) here!
if ($f =~ /\.c$/) {
# Substitute your source directory here!
if (unlink("src/$f")) {
print "Deleted source file $f\n";
} else {
print "Failed to delete source file $f: $!\n";
}
}
}
}
The purpose of the %b is to force rsync to log transfers after they
succeed to avoid deleting a source file that was partially or
unsuccessfully transferred.
Matt
More information about the rsync
mailing list