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