[SOLVED] rsync-Backup-Script does not exclude directories
by snorre from LinuxQuestions.org on (#55KRG)
Hi and a very good afternoon to all of you!
I am trying to backup a Raspberry Pi on my QNAP NAS and therefore created a bash-script,
which should then be triggered via crontab.
I want to exclude some special folders, like the ones from docker, and have therefore
created an exclude file which I would like to use as parameter for the rsync command.
Long story short. Here is what I have done so far...
Code:#!/bin/bash
readonly MOUNT_POINT='/mnt/nfs/backup'
readonly TARGET="${MOUNT_POINT}/Pi3A"
readonly EXCLUDEFILE='exclude.txt'
SOURCES=(/mnt/sda1)
# rSync Switches
readonly RSYNCPARAMS='-avR -hh'
# Configuration von rsync
readonly RSYNCCONFIG='--delete'
# Shortcuts for commands
readonly RSYNC='/usr/bin/rsync'
target="${TARGET}/"
readonly LOG="${0}".log
echo "------------------------------------------------------------------------------" > "${LOG}"
date >> "${LOG}"
echo "" >> "${LOG}"
today=$(date +%d)
echo "" >> "${LOG}"
echo "------------------------------------------------------------------------------" >> "${LOG}"
echo "rSync:" >> "${LOG}"
echo "Params: ${RSYNCPARAMS}" >> "${LOG}"
echo "Config: ${RSYNCCONFIG}" >> "${LOG}"
echo "------------------------------------------------------------------------------" >> "${LOG}"
for source in "${SOURCES[@]}"; do
echo "" >> "${LOG}"
echo "Synchronizing directory \"${source}\" ..." >> "${LOG}"
${RSYNC} ${RSYNCPARAMS} --exclude-from="${EXCLUDEFILE}" ${RSYNCCONFIG[@]} ${source} ${target}${today} >> "${LOG}" 2>&1
if [ ${?} -ne 0 ]; then
ERROR=1
fi
echo "------------------------------------------------------------------------------" >> "${LOG}"
done
echo "" >> "${LOG}"
echo "------------------------------------------------------------------------------" >> "${LOG}"As far as I understood different manuals and descriptions, the path given in the config
file must be relative to the source.
So in my case the source path is
/mnt/sda1
and this is what I tried so far without success...
Code:# tried this
/sda1/lost+found
#tried that
mnt/sda1/lost+foundThe folder lost+found was copied to the server in either case.
Any Ideas?
Many thanks in advance,
Mike


I am trying to backup a Raspberry Pi on my QNAP NAS and therefore created a bash-script,
which should then be triggered via crontab.
I want to exclude some special folders, like the ones from docker, and have therefore
created an exclude file which I would like to use as parameter for the rsync command.
Long story short. Here is what I have done so far...
Code:#!/bin/bash
readonly MOUNT_POINT='/mnt/nfs/backup'
readonly TARGET="${MOUNT_POINT}/Pi3A"
readonly EXCLUDEFILE='exclude.txt'
SOURCES=(/mnt/sda1)
# rSync Switches
readonly RSYNCPARAMS='-avR -hh'
# Configuration von rsync
readonly RSYNCCONFIG='--delete'
# Shortcuts for commands
readonly RSYNC='/usr/bin/rsync'
target="${TARGET}/"
readonly LOG="${0}".log
echo "------------------------------------------------------------------------------" > "${LOG}"
date >> "${LOG}"
echo "" >> "${LOG}"
today=$(date +%d)
echo "" >> "${LOG}"
echo "------------------------------------------------------------------------------" >> "${LOG}"
echo "rSync:" >> "${LOG}"
echo "Params: ${RSYNCPARAMS}" >> "${LOG}"
echo "Config: ${RSYNCCONFIG}" >> "${LOG}"
echo "------------------------------------------------------------------------------" >> "${LOG}"
for source in "${SOURCES[@]}"; do
echo "" >> "${LOG}"
echo "Synchronizing directory \"${source}\" ..." >> "${LOG}"
${RSYNC} ${RSYNCPARAMS} --exclude-from="${EXCLUDEFILE}" ${RSYNCCONFIG[@]} ${source} ${target}${today} >> "${LOG}" 2>&1
if [ ${?} -ne 0 ]; then
ERROR=1
fi
echo "------------------------------------------------------------------------------" >> "${LOG}"
done
echo "" >> "${LOG}"
echo "------------------------------------------------------------------------------" >> "${LOG}"As far as I understood different manuals and descriptions, the path given in the config
file must be relative to the source.
So in my case the source path is
/mnt/sda1
and this is what I tried so far without success...
Code:# tried this
/sda1/lost+found
#tried that
mnt/sda1/lost+foundThe folder lost+found was copied to the server in either case.
Any Ideas?
Many thanks in advance,
Mike