2

So, I'm writing a backup script, and wanted to skip .iso files.

If I use the command from the command line, everything works fine:

rsync -a --delete --exclude='*.iso' /home/user/Desktop/Work /mnt/profile/Desktop/

But, when I try to use it inside my script, is doesn't get the "EXCLUDE" settings, and proceed to copy .iso files. This is the script:

#!/bin/bash
set -e

SRC_DIR="/home/user/Desktop/Work"
DST_MOUNTPOINT="/mnt/profile"
DST_DIR="/mnt/profile/Desktop/"
OPTIONS=" --exclude='*.iso' "

mountpoint -q $DST_MOUNTPOINT || mount $DST_MOUNTPOINT

rsync -a --delete $OPTIONS $SRC_DIR $DST_DIR

If I run the script, get its PID and check /proc/PID/cmdline, the EXCLUDE settings is there.

What I'm doing wrong?

0

1 Answer 1

5

You're putting quotes on the exclude pattern.

OPTIONS=" --exclude='*.iso' "
rsync $OPTIONS

Here, OPTIONS contains <space>--exclude='*.iso'<space>. Since it's not quoted on the rsync command line, word-splitting happens, removing the spaces at the ends. But the single-quotes in the string remain, and are passed to rsync. The pattern doesn't match since you're not likely to have file names with quotes at the start and the end.

Remove the extra quotes (and the spaces) and quote your variables:

OPTIONS="--exclude=*.iso"
rsync "$OPTIONS" "$SRC_DIR" "$DST_DIR"
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.