unix - rsync - filter question

S

Slickuser

I know this not might be the group to post this question but I want to
get an answer.

I will using Perl to Unix command.


Man: http://samba.anu.edu.au/ftp/rsync/rsync.html
I cannot get my filters to work.
I want everything to rsync from /abc/* to /backup/* and delete
destination if tge source is not there but don't delete or touch /
backup/two
Help please?
I have these directories
dirs in /abc: one three fours five six
dirs in /backup: two
This will back up everything and delete /backup/two/
rsync -q --delete -avz /abc/ /backup/
this doesn't work
rsync -q --delete -avz /abc/ /backup/ --filter='protect /backup/two/
*'
rsync -q --delete -avz /abc/ /backup/ --filter='protect /backup/two/'
before::::
dirs in /abc: one three fours five six
dirs in /backup: two
after:
rsync -q --delete -avz /abc/ /backup/
dirs in /abc: one three fours five six
dirs in /backup: one three fours five six
I want this::
before::::
dirs in /abc: one three fours five six
dirs in /backup: two
after:
dirs in /abc: one three fours five six
dirs in /backup: one two three fours five six
if has:
before::::
dirs in /abc: one three fours five six
dirs in /backup: two
after:
dirs in /abc: one three fours five six
dirs in /backup: one two three fours five six
next rsync
dirs in /abc: one three
dirs in /backup: one two three fours five six
this will become
dirs in /abc: one three
dirs in /backup: one two three
 
S

smallpond

I know this not might be the group to post this question but I want to
get an answer.

I will using Perl to Unix command.

Man:http://samba.anu.edu.au/ftp/rsync/rsync.html
I cannot get my filters to work.
I want everything to rsync from /abc/* to /backup/* and delete
destination if tge source is not there but don't delete or touch /
backup/two
Help please?
I have these directories
dirs in /abc: one three fours five six
dirs in /backup: two
This will back up everything and delete /backup/two/
rsync -q --delete -avz /abc/ /backup/
this doesn't work

1) this is not valid perl
2) rsync does not have an error message "doesn't work"

please post a perl question and an actual result.
 
S

Slickuser

Rsync is part of unix, but I'm using perl to call it.
Posting here to see if someone has use rsync before.


#!/usr/local/bin/perl

use warnings;
use strict;

#my $run = "rsync -q --delete -avz /abc/ /backup/ ";
my $run = "rsync -q --delete -avz /abc/ /backup/ --filter='protect /
backup/two/*' ";

print $run ."\n";
system($run);

Executing the perl script:
rsync error: syntax or usage error (code 1) at main.c(1013)
 
S

smallpond

Rsync is part of unix, but I'm using perl to call it.
Posting here to see if someone has use rsync before.

#!/usr/local/bin/perl

use warnings;
use strict;

#my $run = "rsync -q --delete -avz /abc/ /backup/ ";
my $run = "rsync -q --delete -avz /abc/ /backup/ --filter='protect /
backup/two/*' ";

print $run ."\n";
system($run);

Executing the perl script:
rsync error: syntax or usage error (code 1) at main.c(1013)

Weird. I would have expected it to print the command
before it got the error. I'm stumped.
 
S

Slickuser

Weird.  I would have expected it to print the command
before it got the error.  I'm stumped.- Hide quoted text -

rsync -q --delete -avz /abc/ /backup/ --filter='protect /backup/two/
*'


Yah, it does have the command print. Not using the right --filter
option.
 
T

Tim Greer

Slickuser said:
rsync -q --delete -avz /abc/ /backup/ --filter='protect /backup/two/
*'


Yah, it does have the command print. Not using the right --filter
option.

The rule of thumb, is to ensure the command you want to run with exec()
or system() be ran manually on the command line and ensure that it
works normally, before you introduce it in a script and expect it to
work. Thus, the issue is not (yet) a Perl related problem. The error
output is from rsync, there's nothing special related to Perl in this
equation at this time. Be sure you test run the rsync command on the
command line first. Once you remedy that, your problem should be
resolved (assuming there aren't other aspects involved in the Perl code
after the fact).
 
J

Jim Gibson

smallpond said:
Weird. I would have expected it to print the command
before it got the error. I'm stumped.

In Unix, errors are usually printed to STDERR, which is unbuffered (or,
for the pedantic among us, "autoflushed"). However, the print
statements writes to STDOUT, which is buffered and non-autoflushed.
Thus, one often sees error messages before regular output even if the
errors occur later.
 
T

Tad J McClellan

In Unix, errors are usually printed to STDERR, which is unbuffered (or,
for the pedantic among us, "autoflushed").


Errr, no, STDERR is unbuffered if we're to believe the man page.

man 3 stderr

...

CONSIDERATIONS
The stream stderr is unbuffered.
 
J

Jim Gibson

Tad J said:
Errr, no, STDERR is unbuffered if we're to believe the man page.



...

CONSIDERATIONS
The stream stderr is unbuffered.

I suspect that the term "unbuffered" means different things to
different people.
 
P

Peter J. Holzer

STDERR is a Perl stream. rsync isn't written in Perl, so this is
irrelevant for the operation of rsync (and doubly so for the effects on
the script in question - clearly rsync has to flush any buffers before
it exits, or they wouldn't be output at all).

stderr is a C stream, so it would be relevant for rsync. But C doesn't
have "autoflush", only block-buffered, line-buffered, and unbuffered
streams.
I suspect that the term "unbuffered" means different things to
different people.

To me "buffered output" means that the I/O-functions don't write
directly to the file handle. Instead they write into a fixed size
buffer, which is flushed if it gets full or if some other condition
which requires flushing occurs. "Unbuffered output" means that the
I/O-functions either write directly to the file handle or the buffer is
only one byte.

In C, stderr is really unbuffered. If you write a string which is larger
than the buffer like this:

char x[8002];
for (int i = 0; i < 8000; i++) {
x = 'a';
}
x[8000] = '\n';
x[8001] = '\0';
fprintf(stderr, x);
sleep(1);
return 0;

depending on the implementation you either see a single write of 8001
bytes, or 8001 writes of a single byte. If you use stdout instead of
stderr, with a buffer size of 4096 bytes, you see two writes: 4096 bytes
are written immediately, and the rest (3905 bytes) are written after the
sleep (actually after the return from main, but you don't see that with
strace).

In Perl (or at least in perl), STDERR is autoflushed.

my $x = ("a" x 8000) . "\n";
print STDERR $x;
sleep(1);

You see two writes: First 4096 bytes (the buffer is full and must be
flushed), then 3905 bytes (the buffer is autoflushed), and only then you
see the sleep.

hp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top