I have a shell script with hard coded arguments that works:
Code:
#!/bin/sh
DATE=`date "+%Y-%m-%d-%H:%M"`
rsync -avhPHS -x --exclude="/*/.adobe/" \
--exclude="/*/.cache/" \
--exclude="/*/.dbus/" \
--exclude="/*/.gvfs/" \
--exclude="/*/.macromedia/" \
--exclude="/*/.thumbnails/" \
--link-dest=/mnt/backup/home/current \
/home/ /mnt/backup/home/$DATE
rm -f /mnt/backup/home/current
ln -s $DATE /mnt/backup/home/current
sync
To make things easier as my needs change, I set the rsync arguments to easily changeable variables:
Code:
#!/bin/sh
DATE=`date "+%Y-%m-%d-%H:%M"`
OPT="-avhPHS -x"
EXCLUDE="--exclude=\"/*/.adobe/\" --exclude=\"/*/.cache/\" --exclude=\"/*/.dbus/\" --exclude=\"/*/.gvfs/\" --exclude=\"/*/.macromedia/\" --exclude=\"/*/.thumbnails/\""
SOURCE=/home/
DEST="/mnt/backup/home/${DATE}"
LNDEST="--link-dest=/mnt/backup/home/current"
rsync $OPT $EXCLUDE $LNDEST "$SOURCE" "$DEST" ||
echo "error(s) occurred during sync"
## "#????????????" removes "--link-dest=" from $LNDEST
rm "${LNDEST#????????????}" ||
echo "Error: ${LNDEST#????????????} can not be removed"
ln -s "$DATE" "${LNDEST#????????????}" ||
echo "Error: Creating symbolic link \"${LNDEST#????????????}\" to \"$DATE\" failed"
sync
However rsync does not end up excluding anything. If I place fallowing line in the script:
Code:
echo rsync $OPT $EXCLUDE $LNDEST "$SOURCE" "$DEST"
It returns
Code:
rsync -avhPHS -x --exclude="/*/.adobe/" --exclude="/*/.cache/" --exclude="/*/.dbus/" --exclude="/*/.gvfs/" --exclude="/*/.macromedia/" --exclude="/*/.thumbnails/" --link-dest=/mnt/backup/home/current /home/ /mnt/backup/home/2016-07-26-23:09
Just as I would expect, but rsync seems not to be arware of the exclude arguments.
I have also tried the fallowing additional definitions for EXCLUDE:
Code:
EXCLUDE='--exclude="/*/.adobe/" \
--exclude="/*/.cache/" \
--exclude="/*/.dbus/" \
--exclude="/*/.gvfs/" \
--exclude="/*/.macromedia/" \
--exclude="/*/.thumbnails/" \
'
EXCLUDE="--exclude=\"/*/.adobe/\" --exclude=\"/*/.cache/\" --exclude=\"/*/.dbus/\" --exclude=\"/*/.gvfs/\" --exclude=\"/*/.macromedia/\" --exclude=\"/*/.thumbnails/\""
EXCLUDE='--exclude="/*/.adobe/" --exclude="/*/.cache/" --exclude="/*/.dbus/" --exclude="/*/.gvfs/" --exclude="/*/.macromedia/" --exclude="/*/.thumbnails/"'
EXCLUDE='--exclude="*/.adobe/" --exclude="*/.cache/" --exclude="*/.dbus/" --exclude="*/.gvfs/" --exclude="*/.macromedia/" --exclude="*/.thumbnails/"'
EXCLUDE='--exclude="/*/.adobe" --exclude="/*/.cache" --exclude="/*/.dbus" --exclude="/*/.gvfs" --exclude="/*/.macromedia" --exclude="/*/.thumbnails"'
EXCLUDE='--exclude='/*/.adobe' --exclude='/*/.cache' --exclude='/*/.dbus' --exclude='/*/.gvfs' --exclude='/*/.macromedia' --exclude='/*/.thumbnails''
EXCLUDE="--exclude='*/.adobe' --exclude='*/.cache' --exclude='*/.dbus' --exclude='*/.gvfs' --exclude='*/.macromedia' --exclude='*/.thumbnails'"
EXCLUDE="--exclude=\"/*/.adobe/\" \ --exclude=\"/*/.cache/\" \ --exclude=\"/*/.dbus/\" \ --exclude=\"/*/.gvfs/\" \ --exclude=\"/*/.macromedia/\" \ --exclude=\"/*/.thumbnails/\""
None of these have worked.
What did work was the first script without argument variables, and setting EXCLUDE to equal "--exclude-from=/home/USER/scripts/exclude.list". However, I'd like to maintain the exclude list within the script itself instead of a separate file.
This also works so I know the problem is with the EXCLUDE variable and not one of the other variables:
Code:
rsync $OPT --exclude="/*/.adobe/" --exclude="/*/.cache/" --exclude="/*/.dbus/" --exclude="/*/.gvfs/" --exclude="/*/.macromedia/" --exclude="/*/.thumbnails/" $LNDEST "$SOURCE" "$DEST"