Find the answer to your Linux question:
Results 1 to 5 of 5
I want to use an rsync script to do backups. I'm not sure how to use regular expressions for OPT in the script and could use some help. This is ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie
    Join Date
    Dec 2008
    Posts
    166

    rsync backup script: how to use quotes?


    I want to use an rsync script to do backups. I'm not sure how to use regular expressions for OPT in the script and could use some help.
    This is the script I am using:
    #!/bin/bash

    # Flash backup script


    #The source directory:
    SRC="/home/joe/"

    #The target directory:
    TRG="/media/linux/joe/"

    #The rsync options:
    OPT="-av --numeric-ids --delete --delete-excluded --filter=merge /home/joe/bin/scripts/flash-filter-rule.txt"

    #Execute the backup
    rsync $OPT $SRC $TRG
    This gave me an error:
    joe@crunchbang:~/bin/scripts$ bash flash-backup.txt
    unexpected end of filter rule: merge
    rsync error: syntax or usage error (code 1) at exclude.c(901) [client=3.0.9]

    I also tried quoting the OPT like this:
    OPT="-av --numeric-ids --delete --delete-excluded --filter='merge /home/joe/bin/scripts/flash-filter-rule.txt'"
    Unknown filter rule: `'merge'

    and
    OPT="-av --numeric-ids --delete --delete-excluded --filter=merge\ /home/joe/bin/scripts/flash-filter-rule.txt"
    Unknown filter rule: `merge\'

    How do I write this to merge in the filter rule file?

    Thanks

  2. #2
    Linux Engineer
    Join Date
    Dec 2013
    Posts
    1,374
    Quote Originally Posted by JoeS View Post
    I want to use an rsync script to do backups. I'm not sure how to use regular expressions for OPT in the script and could use some help.


    This gave me an error:
    joe@crunchbang:~/bin/scripts$ bash flash-backup.txt
    unexpected end of filter rule: merge
    rsync error: syntax or usage error (code 1) at exclude.c(901) [client=3.0.9]

    I also tried quoting the OPT like this:
    OPT="-av --numeric-ids --delete --delete-excluded --filter='merge /home/joe/bin/scripts/flash-filter-rule.txt'"
    Unknown filter rule: `'merge'

    and
    OPT="-av --numeric-ids --delete --delete-excluded --filter=merge\ /home/joe/bin/scripts/flash-filter-rule.txt"
    Unknown filter rule: `merge\'

    How do I write this to merge in the filter rule file?

    Thanks
    I think you need:
    Code:
    OPT='-av --numeric-ids --delete --delete-excluded --filter="merge /home/joe/bin/scripts/flash-filter-rule.txt"'

  3. #3
    Linux Newbie
    Join Date
    Dec 2008
    Posts
    166
    Quote Originally Posted by gregm View Post
    I think you need:
    Code:
    OPT='-av --numeric-ids --delete --delete-excluded --filter="merge /home/joe/bin/scripts/flash-filter-rule.txt"'
    That gave an error:
    joe@crunchbang:~/bin/scripts$ bash flash-backup.txt
    Unknown filter rule: `"merge'
    rsync error: syntax or usage error (code 1) at exclude.c(817) [client=3.0.9]

  4. #4
    Linux Engineer
    Join Date
    Dec 2013
    Posts
    1,374
    I've no idea why quoting doesn't work. According to the man page it should.In any event, also as per the man page this worked for me:

    Code:
    OPT="-av --numeric-ids --delete --delete-excluded --filter=merge_./flash-filter-rule.txt"
    *that was how I tested - it should work with you full path too:

    Code:
    OPT="-av --numeric-ids --delete --delete-excluded --filter=merge_/home/joe/bin/scripts/flash-filter-rule.txt"
    Last edited by gregm; 05-17-2014 at 01:51 PM.

  5. #5
    Linux Newbie
    Join Date
    Dec 2008
    Posts
    166
    Thanks, that worked
    I didn't know about the _ in _merge. I used it without in the cli, but it doesn't work that way in a script.

Posting Permissions

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