Visit Our UNIX and Linux User Community

rsync - exclude statement not working

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting rsync - exclude statement not working
# 1  
Old 08-20-2008
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:

as well as:

and also:

neither seems to work.

# 2  
Old 08-21-2008

Here's a sample that I use to try things with rsync:

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

# Set, display environment with local command version.

set +o nounset
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


# Remove previous debris.


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 " 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 " $S:"
ls -lgG $S

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 " Results from rsync:"
rsync \
--verbose \
-abv --exclude=/not-backed-up/ --delete \
--backup-dir=$B --suffix=.orig $S/ $D/

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

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

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

exit 0

% ./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

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

1 directory, 5 files
|-- 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:

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

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/
[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
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

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:
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

Previous Thread | Next Thread
Test Your Knowledge in Computers #504
Difficulty: Medium
Typically, programs operate in a reverse-linear flow of control.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rsync exclude & include?

hi I have a few folders and a few files , for example Directory A B C D E Files 1 2 3 4 5 I want B directory and "2" File that does not sync But other directories and file sync What is the solution ? Is there a way to sync time is under one minute? os centos 6.8 thanks... (5 Replies)
Discussion started by: mnnn
5 Replies

2. Solaris

TAR exclude is not working !

I have solaris 10 and my following exclude is not working: tar -cvf /export/home/backups/$audit-Data-$useday.bkup.tar /Data --exclude=/Data/ssg/output a /Data/ssg/output/ 0K a /Data/ssg/output/ssg-ported508.txt 107142K a /Data/ssg/output/ssg-ported747.txt 1801K a... (4 Replies)
Discussion started by: mrn6430
4 Replies

3. UNIX for Dummies Questions & Answers

Exclude txt file in rsync

Hi Folks, I'm using rsync on Solaris 10 to backup a web server and need to exclude the cache and tmp directories. The man pages and google on rsync --exclude are ambiguous but I have tried--exclude=".*" and --exclude/remote_server/absolute_path with success only on the tmp files. Rather than make... (2 Replies)
Discussion started by: SmokeyJoe
2 Replies

4. Shell Programming and Scripting

Little help with rsync --exclude

Loving the rsync command and beginning to write some scripts with it. However I'm hung up on the --exclude function. Script is tested and works great BEFORE I put the --omit in. What am I doing wrong in my syntax? rsync $OPTS /cis/cloverleaf/cis6.0/integrator/... (2 Replies)
Discussion started by: B_ROX
2 Replies

5. Shell Programming and Scripting

working with tar exclude command

i have issue with tar, let me explain when i run below command it works perfectly as usual. tar -cvf /tmp/temp.tar --exclude="exclusion expression" dir my requirement is --exclude="exclusion expression" will come from another variable. so when i execute below command: tar -cvf... (2 Replies)
Discussion started by: ajayyadavmca
2 Replies

6. Red Hat

rsync not working

I have tried rsync command as shown below, (if directory doesn't not exist on destination, i needs to create directories and sub directories through rsync at the destination server.) Note: Here /thaks/new/28/ directories doesn't exists on destination, How to create this on destination via rsync... (1 Reply)
Discussion started by: thakshina
1 Replies

7. AIX

exclude files not working

HI, I have upgraded nim master and client to TL8,SP6. Now when the mksysb backup ran from master,it is not excluding directories specified in /etc/exclude.rootvg in the client.Instead,mksysb is getting created for all the file systems in the rootvg. This problem only appeared after the TL... (3 Replies)
Discussion started by: to_bsr
3 Replies

8. Shell Programming and Scripting

rsync exclude option

Hi Frdz, i am using rsync to transfer files from source to destination. but i have one criteria like i have to tranfer only links from source to destination. in home/test/po folder i have kiran/test1 -> /home/test/lo/fg kiran/test2 -> /home/test/lo/fg2 like links are available.... (1 Reply)
Discussion started by: KiranKumarKarre
1 Replies

9. Shell Programming and Scripting

Creating and using a /.rsync/exclude

Hello all, Everyone has been awesome assisting with my rsync script... Now I want to clean it up. I think the best way for me to exclude many files might be to use a rsync exclude file. So in my script I add So now then, here is my .rsync/exclude... So what is happening is the... (0 Replies)
Discussion started by: komputersman
0 Replies

10. UNIX for Dummies Questions & Answers

Rsync not working :(

Hi all, I installed Rsync on my Solaris 8 but when I ran it, it returns ./rsync: fatal: open failed: No such file or directory Killed Please help. Thanks. (3 Replies)
Discussion started by: stancwong
3 Replies

Featured Tech Videos