Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to backup some folders with rsync launched on daemon mode. Basically the client launch this command:

   rsync --delete -avz -R -e "ssh -i ${KEY}" ${SERVER}::${MODULE} {DST_DIR}

the server has the public key on its authorized_keys file:

    command="rsync --server --daemon --config /root/rsync.conf"

and here is the rsync.conf file containing folders I want to backup:

    uid=0
    gid=0
    read only = true
    use chroot = true
    [backup]
    path = /root
    path = /etc

The problem here is that the content of these folders is copied and not its absolute path. I would like /etc/etc_content and /root/root_content in my ${DST_DIR} and what I get is the content of /etc (I presume /root is synchronized first, and then /etc, which delete /root content... Ouch).

I am pretty sure there is a way to force rsync to preserve absolute path. I have tried with the -R option without success. I have also tried without use chroot.

How can I get it through?

Many thanks

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

You are right with "-R" option to use relative paths but it works a bit different way. The ${MODULE} exports exactly the portion of rsync server's filesystem which is defined by "path" parameter.

You should have only one "path" parameter per "module" section defined. This explains why you can see /root content first and /etc later as it seems to be overwritten when multiple path parameters are specified.

I would either try to define a module per a directory I want to backup

uid=0
gid=0
read only = true
use chroot = true

[root]
path = /root

[etc]
path = /etc

and then call rsync over all these modules

for MODULE in root etc; do
  rsync -avzR $SERVER::$MODULE $DST_DIR/$MODULE
done

Or I would export wider portion of the server's filesystem with single module section

uid=0
gid=0
read only = true
use chroot = true

[root]
path = /

And backup requied directories

rsync -avzR $SERVER::$MODULE/root  $SERVER::$MODULE/etc $DST_DIR

Both ways will preserve the original/absolute directory structure you requested.

share|improve this answer
    
Thanks for your answer; The fact is I want to restrict the list on client side (If a cracker get access to backup server, he could decide to switch backup files to /etc/shadow for instance) and I would like if possible a unique [backup] module. I think we can manage this with filter or include/exclude rsync.conf options. –  philippe Aug 26 '13 at 19:38
add comment

I have found a way with the include options; my rsync.conf file now looks like this:

    uid=0
    gid=0
    read only = true
    use chroot = true
    [backup]
    path = /
    include /etc/*** /root/*** /usr/local/etc/***
    exclude /***

I can then retrieve the folders with their absolute path, but another trouble appears:

The problem here is that the synchronization is only working for included directories directly below / aka /etc/* and /root/* and it is not working for /usr/local/etc/*

The same problem occurs when I tries with the include from keyword and fill these folders into the specified included_from file.

I am kind of desperate; Either this is not possible to perform what I want with rsync, or I am missing something obvious? man explanation for rsync is quite tough. dsumsky, thanks for you answer, and I am trying to think I should adopt your solution after all.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.