Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

rsync not exclusing.

  • 18-06-2005 05: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