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"
Here's a sample that I use to try things with rsync:
#!/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:
% ./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