Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: rsync command needs help exclude command not excluding

  1. #1
    Join Date
    Sep 2011
    Beans
    180
    Distro
    Ubuntu

    Question rsync command needs help exclude command not excluding

    Here's what I'm trying to do - back up all the folders in my home directory except /Videos/.

    This is the command I have made:
    Code:
    rsync --progress -rEog --exclude-from="~/Videos" /home/alex /media/backup/12.04-Precise-backup_4.23.2012/
    I've also tried without the quotes and = sign. I've also tried this:

    Code:
    rsync --progress -rEog --exclude home/alex/Videos /home/alex /media/backup/12.04-Precise-backup_4.23.2012/
    But all of them still create the same Videos folder..

    What am I doing wrong?

  2. #2
    Join Date
    Jun 2009
    Location
    SW Forida
    Beans
    Hidden!
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: rsync command needs help exclude command not excluding

    I do not fully understand rsync. It has many options and parameters. I just copied something that worked for me.

    I think the --exclude-from expects a file name with the list of excludes.
    see
    man rsync
    --exclude=PATTERN exclude files matching PATTERN
    --exclude-from=FILE read exclude patterns from FILE
    This works for me. But I want to exclude more than just my .thumbnails and want to create a list and use the --exclude-from=file

    rsync -aurvlP --exclude '.thumbnails' /home /mnt/Backup
    For more info on UEFI boot install & repair - Regularly Updated :
    http://ubuntuforums.org/showthread.php?t=2147295
    Please use Thread Tools above first post to change to [Solved] when/if answered completely.

  3. #3
    Join Date
    Feb 2007
    Beans
    185

    Re: rsync command needs help exclude command not excluding

    I thought I got it working but was wrong. This is weird.

    [edit]

    Try this:
    Code:
    cd ~
    rsync --progress -rEog --exclude=/Videos /home/alex/ /media/backup/12.04-Precise-backup_4.23.2012/
    Important things I learned from the man page and from testing:

    The exclude pattern starting with a slash (/) means that it's relative to the transfer-root, not the filesystem root.

    When you include a trailing slash in you transfer root, that directory becomes the transfer root, otherwise the parent directory is. Example:

    This should create the directory 'alex' in the destination directory, ending up with /destination/alex/files
    Code:
    rsync -r /home/alex /destination
    This, on the other hand, copies each file within /home/alex to the destination without creating an 'alex' directory. Notice the tailing slash on the source directory:
    Code:
    rsync -r /home/alex/ /destination
    This will create various subdirectories in the destination:

    So, back to your command, if you DO NOT include the trailing slash in the source, your pattern would need to be /alex/Videos whereas if you DO include the trailing slash in your source, your pattern would be /Videos because the trailing slash on the source changes your transfer-root.
    Last edited by gsgleason; April 23rd, 2012 at 08:43 PM.

  4. #4
    Join Date
    Sep 2011
    Beans
    180
    Distro
    Ubuntu

    Re: rsync command needs help exclude command not excluding

    Quote Originally Posted by gsgleason View Post
    I thought I got it working but was wrong. This is weird.

    [edit]

    Try this:
    Code:
    cd ~
    rsync --progress -rEog --exclude=/Videos /home/alex/ /media/backup/12.04-Precise-backup_4.23.2012/
    Important things I learned from the man page and from testing:

    The exclude pattern starting with a slash (/) means that it's relative to the transfer-root, not the filesystem root.

    When you include a trailing slash in you transfer root, that directory becomes the transfer root, otherwise the parent directory is. Example:

    This should create the directory 'alex' in the destination directory, ending up with /destination/alex/files
    Code:
    rsync -r /home/alex /destination
    This, on the other hand, copies each file within /home/alex to the destination without creating an 'alex' directory. Notice the tailing slash on the source directory:
    Code:
    rsync -r /home/alex/ /destination
    This will create various subdirectories in the destination:

    So, back to your command, if you DO NOT include the trailing slash in the source, your pattern would need to be /alex/Videos whereas if you DO include the trailing slash in your source, your pattern would be /Videos because the trailing slash on the source changes your transfer-root.
    So as far as the trailing slash goes - how would I make sure to specify to exclude the folder /alex/Videos/ from the recursive copy?

  5. #5
    Join Date
    Aug 2011
    Beans
    343
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: rsync command needs help exclude command not excluding

    At the risk of stating the obvious, rsync can be confusing. To do what I think you are trying to do, 'rsync -av --except Videos /home/alex/ /media/backup/' should do it - I simplified the destination a little. That should copy everything in alex to /media/backup except anything named Videos (file or directory). Note /home/alex/. If I had used /home/alex it would have copied the tree rooted at alex to /media/backup, so you would see /media/backup/alex/, not /media/backup/<contents of alex>. Of course the alex directory would have the entire tree. Does this help? The -a switch combines a lot of switches. For details, see the man page.

  6. #6
    Join Date
    Sep 2011
    Beans
    180
    Distro
    Ubuntu

    Question Re: rsync command needs help exclude command not excluding

    Quote Originally Posted by agillator View Post
    At the risk of stating the obvious, rsync can be confusing. To do what I think you are trying to do, 'rsync -av --except Videos /home/alex/ /media/backup/' should do it - I simplified the destination a little. That should copy everything in alex to /media/backup except anything named Videos (file or directory). Note /home/alex/. If I had used /home/alex it would have copied the tree rooted at alex to /media/backup, so you would see /media/backup/alex/
    Actually, thats fine with me, I can restore from that as well, I have the reverse command just not the command that copies it and the reason I set so many params was to keep the ownership as well as the file properties.

    Quote Originally Posted by agillator View Post
    not /media/backup/<contents of alex>. Of course the alex directory would have the entire tree. Does this help? The -a switch combines a lot of switches. For details, see the man page.
    So what you're saying is instead of using:

    Code:
    rsync --progress -rEog --exclude=/Videos /home/alex/ /media/backup/12.04-Precise-backup_4.23.2012/
    I can use the following:

    Code:
    rsync --progress -rEog --except Videos /home/alex/ /media/backup/12.04-Precise-backup_4.23.2012/
    But that would mean I would also have to cd into the directory itsself then?

  7. #7
    Join Date
    Aug 2011
    Beans
    343
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: rsync command needs help exclude command not excluding

    I must have been asleep - not 'except', but 'exclude'. I am terribly sorry about that, I try to be so careful. However, '--exclude Videos' is correct, no equal sign. The key on whether or not the directory itself is copied or just the contents is the slash at the end of the source: /home/alex/ means the contents of the directory will be copied, /home/alex means the directory and the contents will be copied. Specifically, assume /home/alex contained files name f-one and f-two. /home/alex would result in /media/alex/f-one and /media/alex/f-two at the destination; /home/alex/ would result in /media/f-one and /media/f-two. To omit a directory, '--exclude Videos' or '--exclude Videos/' will work, but '--exclude /Videos' or '--exclude /Videos/' will not (the leading / is the problem).

  8. #8
    Join Date
    Sep 2011
    Beans
    180
    Distro
    Ubuntu

    Wink Re: rsync command needs help exclude command not excluding

    Quote Originally Posted by agillator View Post
    I must have been asleep - not 'except', but 'exclude'. I am terribly sorry about that, I try to be so careful. However, '--exclude Videos' is correct, no equal sign. The key on whether or not the directory itself is copied or just the contents is the slash at the end of the source: /home/alex/ means the contents of the directory will be copied, /home/alex means the directory and the contents will be copied. Specifically, assume /home/alex contained files name f-one and f-two. /home/alex would result in /media/alex/f-one and /media/alex/f-two at the destination; /home/alex/ would result in /media/f-one and /media/f-two. To omit a directory, '--exclude Videos' or '--exclude Videos/' will work, but '--exclude /Videos' or '--exclude /Videos/' will not (the leading / is the problem).
    Alright Alligator ,

    Here comes today bonus challenge - how would I exclude TWO directories? or multiple directories?

  9. #9
    Join Date
    Aug 2011
    Beans
    343
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: rsync command needs help exclude command not excluding

    Two excludes: '--exclude Videos --exclude Audios' for example.

  10. #10
    Join Date
    Sep 2011
    Beans
    180
    Distro
    Ubuntu

    Talking Re: rsync command needs help exclude command not excluding

    Quote Originally Posted by agillator View Post
    two excludes: '--exclude videos --exclude audios' for example.
    friggin score!!!!! :d yes!!!! Thank you alligator!

    :ks

Page 1 of 2 12 LastLast

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
  •