Results 1 to 4 of 4

Thread: Rsync selected directories in users home dir

  1. #1
    Join Date
    Jun 2010
    Beans
    45

    Rsync selected directories in users home dir

    Hi.
    I'm tying to rsync users /home directories to a new server. But I want to only copy selected files and directories.

    typically :

    clubbing80s/.bash_history
    clubbing80s/.bash_logout
    clubbing80s/.bashrc
    clubbing80s/.gitconfig
    clubbing80s/.mysql_history
    clubbing80s/.nano_history
    clubbing80s/.profile
    clubbing80s/.ssh/*

    and exclude anything else.
    I have been playing with variations of

    rsync -av '--include=.ssh/*' '--exclude=*' /home/ /tmp/

    as a test , but I sill get other files / dirs I don't want.

    Any suggestions ?

    GM

  2. #2
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    7,472
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Rsync selected directories in users home dir

    Hi clubbing80s.

    Since you are excluding anything else at the end, you need to include explicitly the the path of the files (clubbing80s/ or */ for all users).

    For me, it is easier to use the option --include-from, and put all include and exclude rules in one file. For example (includes.txt):
    Code:
    + */
    + .bash_history
    + .bash_logout
    + .bashrc
    + .gitconfig
    + .mysql_history
    + .nano_history
    + .profile
    + .ssh/
    + .ssh/*
    - *
    Now, you may be seeing lots of things being copied any way. That is because rync has in my opinion the 'bad practice' of always copying the whole directory tree, even if it's not copying any file under it. You can avoid that using the option --prune-empty-dirs (or -m for short).

    Considering all of the above, this should work:
    Code:
    rsync -avm --include-from=includes.txt  /home/  /tmp/
    Hope it helps, and tell us how it goes.
    Regards.

  3. #3
    Join Date
    Jun 2010
    Beans
    45

    Wink Re: Rsync selected directories in users home dir

    Works like a charm.

    Many Thanks !!!

    G

  4. #4
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    7,472
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Rsync selected directories in users home dir

    Great! Please mark the thread solved when you have the chance.

    Regards.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •