0

I am using Perl library File::RsyncP.

This moment script copies all files, but I need to use extension and later pattern for example 2019*.xml

I don´t know how to filter files by extension. I have tried following     

I take a connection into localhost I have

/home/raimo/A/SRC/srcDirectory/1.xml
/home/raimo/A/SRC/srcDirectory/2.xml
/home/raimo/A/SRC/srcDirectory/3.txt

here I would like to copy only xml files into    

I have tried:

rsyncCmd => "/bin/rsync -avz --include '*.xml' srcDirectory destDirectory ", and I have tired rsyncCmd => "/bin/rsync -avz --include '*.xml' destDirectory srcDirectory "

/home/raimo/A/SRC/destDirectory

my $rs = File::RsyncP->new({
        logLevel   => 5,
        rsyncCmd   => "/bin/rsync --include '*.xml'",   #check if possible to filter
        rsyncArgs  => [
                "--numeric-ids",
                "--perms",
                "--owner",
                "--group",
                "--devices",
                "--links",
                "--ignore-times",
                "--block-size=700",
                "--relative",
                "--recursive",
                "--verbose"
            ],
    });
...
 # Receive files from remote srcDirectory to local destDirectory
 # # by running rsyncCmd with rsyncArgs.
 $rs->remoteStart(1, srcDirectory);
Corion
  • 3,855
  • 1
  • 17
  • 27
Raimo
  • 25
  • 9
  • How would you exclude the files using a plain `rsync` command line? – Corion Jan 10 '19 at 11:38
  • Hi, I haven´t used plain rsync but, there is mentioned on internet pages. That following syntax should work /bin/rsync -avz --exclude '*.typ' source/ destination/. With perl library that I I am using. source and destination has to write elsewhere... # Receive files from remote srcDirectory to local destDirectory
    # # by running rsyncCmd with rsyncArgs. $rs->remoteStart(1, srcDirectory); # $rs->go(destDirectory); #
    – Raimo Jan 10 '19 at 12:01
  • So, maybe follow what the internet pages suggest? – Corion Jan 10 '19 at 12:02
  • ok, after pause, I try to write source and destination, into both places after rsync command. and into libraries place... Now I take a pause of one hour – Raimo Jan 10 '19 at 12:08
  • `--include '*.pl' --exclude '*'` - you first include all `.pl` files, but then exclude all files - that makes little sense. Maybe explain which files you want to include and which files you want to exclude and show some examples. – Corion Jan 10 '19 at 12:10
  • my purpose is include \*.xml files I have tried: rsyncCmd => "/bin/rsync -avz --include '\*.xml' srcDirectory destDirectory ", and I have tired rsyncCmd => "/bin/rsync -avz --include '\*.xml' destDirectory srcDirectory ",.. – Raimo Jan 10 '19 at 14:07
  • Can you please [edit] your post and add the above comment to it? Maybe also add some example directory structure and explain what `rsync` does and also what you want it to do? – Corion Jan 10 '19 at 14:15
  • hi, I don´t have enough points for chat. I have updated my question – Raimo Jan 10 '19 at 15:14
  • Are there other files in `/home/raimo/A/SRC/srcDirectory/` that you want to avoid? https://stackoverflow.com/questions/14655834/rsync-include-option-does-not-exclude-other-files shows that your first approach should be what you want, `--include '*.xml' --exclude '*'` – Corion Jan 10 '19 at 15:19
  • exclude is not necessary, only files what match for example with filename2019*.xml. my filename variable comes... word +wildcard +extension (xml) in this case. problem is that File::RsyncP; does not react to --include '*.xml'...instead it copies all files in a directory – Raimo Jan 10 '19 at 15:22
  • Try adding `--include` and `*.xml` to the `rsyncArgs`, not the `rsyncCmd`. – Corion Jan 10 '19 at 15:26
  • I have tried already. rsyncArgs => [ "--numeric-ids", "--perms", "--owner", "--group", "--devices", "--links", "--ignore-times", "--block-size=700", "--relative", "--recursive", "--verbose", "--include '*.xml'",. causes an error Fatal error (bad version): rsync: on remote machine: --include '\*.xml': unknown option – Raimo Jan 10 '19 at 15:33
  • Split it up: `"--include", "*.xml"` – Corion Jan 10 '19 at 15:52
  • ok, I did it. now it copies all files but not xml.Can't chmod(destDirectory/test.xml, 0100777) Can't chown(1000, 1000, destDirectory/test.xml) Can't mtime(1547135663, 1547135663, destDirectory/test.xml) – Raimo Jan 10 '19 at 16:02
  • test.xml was empty, I filled it. test.xml is copied also, but so are all files – Raimo Jan 10 '19 at 16:17
  • exclude txt works perfectly now, but include not work with patterns, you have helped me alot, If I could do filter by pattern, I could maybe put this little by little into production."--include", "*.xml", "--exclude", "*.txt", – Raimo Jan 10 '19 at 16:21

0 Answers0