Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

rsync not exclusing.

  • 18-06-2005 5:16pm
    #1
    Registered Users, Registered Users 2 Posts: 1,865 ✭✭✭


    After a harddrive crash I'm writing a shell script to automatically backup various files using rsync. However the --exclude argument isn't working. Here is the script.
    #! /bin/bash
    THINGS_TO_BACKUP=('.mozilla' '.vim' 'code' '.gaim' '.eclipse' 'bin' '.xmms' '.vimrc')
    EXCLUDE_CMD="--exclude='.mozilla/firefox/p735u1zv.default/Cache/*'"
    cd ${HOME}
    REMOTE_DIR="backup/"
    RSYNC_CMD="rsync -avz --perms ${EXCLUDE_CMD} --delete-excluded ${THINGS_TO_BACKUP[*]} user@remotehost:${REMOTE_DIR}"
    
    echo ${RSYNC_CMD}
    ${RSYNC_CMD}
    

    As you can see I don't want to backup my Firefox cache, but it does get rsynced. The script will print out the command and then execute the command. If I copy and paste the command into a terminal, the cache directory is not backed up, That's what I want.

    The command that's printed and does what I want is:
    rsync -avz --perms --exclude='.mozilla/firefox/p735u1zv.default/Cache/*' --delete-excluded .mozilla .vim code .gaim .eclipse bin .xmms .vimrc user@remotehost:backup/
    


Comments

  • Registered Users, Registered Users 2 Posts: 354 ✭✭AndrewMc


    Syth wrote:
    EXCLUDE_CMD="--exclude='.mozilla/firefox/p735u1zv.default/Cache/*'"
    

    As you can see I don't want to backup my Firefox cache, but it does get rsynced. The script will print out the command and then execute the command. If I copy and paste the command into a terminal, the cache directory is not backed up, That's what I want.

    As far as I can tell, it's to do with how the quote marks are handled in bash. It should work if you use:
    EXCLUDE_CMD=--exclude='.mozilla/firefox/p735u1zv.default/Cache/*'
    

    As I understand it, the outer quote marks are removed, and all internal quote marks are retained. This means it displays the way you want it. When you copy+paste that again, the remaining single quotes are then removed, too, so it works. This second quote removal doesn't happen when executed from the "variable" (not sure why - it just appears to take the whole lot literally). Try this:
    #!/bin/bash
    
    TEST="--exclude=hello"
    echo TEST is ${TEST}
    TEST=--exclude='hello'
    echo TEST is ${TEST}
    TEST="--exclude='hello'"
    echo TEST is ${TEST}
    

    Instead of just running ${RSYNC_CMD}, you could run
    eval ${RSYNC_CMD}
    
    which evaluates the string as if entered from the command line rather than taking it literally.


  • Registered Users, Registered Users 2 Posts: 1,865 ✭✭✭Syth


    That was the problem. Thanks. I used the eval method you used. I thought it was something to do with bash since the copy&pasting worked. Thanks. :)


Advertisement