linux - Incremental back using rsync
2013-09
Romski
I want to sync incremental changes to a remote server using rsync
and --link-dest
. To test it locally I have created the following structure to test locally:
src
d1
f1
d2
f1 # exactly the same src/d1/f1
f2
target
d1
f1 # exactly the same src/d1/f1
I am running the following command to sync incremental changes
rsync -arv --link-dest=/tmp/target/d1 /tmp/src/d2/ /tmp/target/d2
The output is
sending incremental file list
created directory /tmp/target/d2
./
f1
f2
I only expected f2
to be synced as f1
is unchanged. Checking the number of hardlinks on /tmp/target/d1/f1
show that it only has 1 link
$ ls -l target/d1/f1
-rw-rw-r-- 1 user user 3 Jun 22 12:46 target/d1/f1
Answers
Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.
Related Question
linux - rsync as a background process?
Dario
I've been using rsync to sync a bunch of files between my two servers. I set a cron job that would run rsync every minute. However, I'd prefer if I could have it run always, so that files are synced the moment they are changed. What would be the best way to do this?
Thanks.
Related Answers
Doug Harris
If you have inotify in your kernel, check out inotify-tools.
There's an example on that page:
#!/bin/sh
# A slightly complex but actually useful example
inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %f' \
-e close_write /home/billy | while read date time file; do
rsync /home/billy/${file} rsync://[email protected]/backup/${file} && \
echo "At ${time} on ${date}, file ${file} was backed up via rsync"
done