The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
rsync not working thro' cron sm23328 UNIX for Advanced & Expert Users 1 06-20-2008 12:13 PM
rsync not working thro' cron -RH Linux sm23328 UNIX for Dummies Questions & Answers 1 06-19-2008 02:01 PM
Creating and using a /.rsync/exclude komputersman Shell Programming and Scripting 0 03-19-2008 06:13 PM
If statement not working Hazmeister Shell Programming and Scripting 6 12-13-2007 04:33 AM
Rsync not working :( stancwong UNIX for Dummies Questions & Answers 3 02-09-2006 11:23 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-20-2008
em23's Avatar
em23 em23 is offline
Registered User
  
 

Join Date: May 2008
Location: Chicago
Posts: 31
rsync - exclude statement not working

hey all, i'm trying to rsync some dir's and files between servers and i've added an exclude statement, but it still goes out and tries to rsync the directory.

I've tried the following:
--exclude="/export/home/zones/lab"

as well as:
--exclude=/export/home/zones/lab

and also:
--exclude/export/home/zones/lab

neither seems to work.

Thoughts?
  #2 (permalink)  
Old 08-21-2008
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 704
Hi.

Here's a sample that I use to try things with rsync:
Code:
#!/bin/sh

# @(#) s1       Demonstrate rsync features, copy from source to destination.

# Set, display environment with local command version.

set +o nounset
LC_ALL=C ; LANG=C ; export LC_ALL LANG
echo "Environment: LC_ALL = $LC_ALL, LANG = $LANG"
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version "=o" $(_eat $0 $1) rsync
set -o nounset

debug=":"
debug="echo"

# Remove previous debris.

S=source
D=destination
B=backup

rm -rf $S $D
mkdir $S $D

cd $S
echo one >t1
echo two >t2
echo thr >t3
echo fou >t4
echo fiv >t5
cd ..
cp $S/* $D

# Create anomalies, delete one file, create a structure not to be
# copied.

mkdir $S/not-backed-up
touch $S/not-backed-up/a-junk-file
rm $S/t3

echo
echo " Structures:"

tree -F $S
tree -F $D

# Back date the destination.

backdate=$( date --date="5 minutes ago" )
$debug " now = $(date);  backdate = :$backdate:"

touch --date="$backdate" $D/*

echo
echo " $S:"
ls -lgG $S

echo
echo " $D:"
ls -lgG $D

# The easiest way to see what name you should include/exclude
# is to just look at the output when using --verbose and
# put a / in front of the name (use the --dry-run option if
# you're not yet ready to copy any files).
# --dry-run --verbose

echo
echo " Results from rsync:"
rsync \
--verbose \
-abv --exclude=/not-backed-up/ --delete \
--backup-dir=$B --suffix=.orig $S/ $D/

echo
echo " $D, final"
ls -lgG $D

echo
echo " $D/$B"
ls -lgG $D/$B

echo
echo " Diff of $S and $D"
diff -r $S $D

exit 0
Producing:
Code:
% ./s1
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
Linux 2.6.11-x1
GNU bash, version 2.05b.0(1)-release (i386-pc-linux-gnu)
rsync  version 2.6.3  protocol version 28

 Structures:
source
|-- not-backed-up/
|   `-- a-junk-file
|-- t1
|-- t2
|-- t4
`-- t5

1 directory, 5 files
destination
|-- t1
|-- t2
|-- t3
|-- t4
`-- t5

0 directories, 5 files
 now = Thu Aug 21 17:41:20 CDT 2008;  backdate = :Thu Aug 21 17:36:20 CDT 2008:

 source:
total 16
drwxr-xr-x  2 80 Aug 21 17:41 not-backed-up
-rw-r--r--  1  4 Aug 21 17:41 t1
-rw-r--r--  1  4 Aug 21 17:41 t2
-rw-r--r--  1  4 Aug 21 17:41 t4
-rw-r--r--  1  4 Aug 21 17:41 t5

 destination:
total 20
-rw-r--r--  1 4 Aug 21 17:36 t1
-rw-r--r--  1 4 Aug 21 17:36 t2
-rw-r--r--  1 4 Aug 21 17:36 t3
-rw-r--r--  1 4 Aug 21 17:36 t4
-rw-r--r--  1 4 Aug 21 17:36 t5

 Results from rsync:
backup_dir is backup/
building file list ...
[sender] expand file_list to 131072 bytes, did move
[sender] excluding directory not-backed-up because of pattern /not-backed-up/
done
[receiver] expand file_list to 131072 bytes, did move
deleting in .
backed up t3 to backup/t3.orig
deleting t3
delta-transmission disabled for local transfer or --whole-file
t1
t2
t4
t5
backed up t1 to backup/t1.orig
backed up t2 to backup/t2.orig
backed up t4 to backup/t4.orig
backed up t5 to backup/t5.orig
total: matches=0  tag_hits=0  false_alarms=0 data=16

sent 323 bytes  received 100 bytes  846.00 bytes/sec
total size is 16  speedup is 0.04

 destination, final
total 16
drwxr-xr-x  2 168 Aug 21 17:41 backup
-rw-r--r--  1   4 Aug 21 17:41 t1
-rw-r--r--  1   4 Aug 21 17:41 t2
-rw-r--r--  1   4 Aug 21 17:41 t4
-rw-r--r--  1   4 Aug 21 17:41 t5

 destination/backup
total 20
-rw-r--r--  1 4 Aug 21 17:36 t1.orig
-rw-r--r--  1 4 Aug 21 17:36 t2.orig
-rw-r--r--  1 4 Aug 21 17:36 t3.orig
-rw-r--r--  1 4 Aug 21 17:36 t4.orig
-rw-r--r--  1 4 Aug 21 17:36 t5.orig

 Diff of source and destination
Only in destination: backup
Only in source: not-backed-up
Here's a brief explanation:
Quote:
Description of events:

Remove debris and re-create directories source and destination.

Create t1 - t5 in source.

Copy source to destination. This would be the situation where
everything is in sync.

Now we delete one file, and add a directory. This simulates
what often happens in a working directory -- it gets changed.
We decide that we want to keep the extra directory, but not to
have it processed by rsync, so we'll name it in an exclude.

To further simulate real-life, we'll back-date the files in
destination, so that rsync will think that it needs to update
(even though the content may not differ).

Visual trees are produced, as well as details of the objects.

The rsync is run in verbose mode, and the output suggests that
what we desired was obtained.

For the exclude, we need to specify a level down from the
source, because that is taken as the "root".

The directory "backup" holds all the original items that were
updated -- written over.
cheers, drl
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:30 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0