Я хочу указать параметры исключения для tar в сценарии оболочки, но он не работает. Эта часть кода:
#!/bin/bash
backuprootdir=/usr/local/misc
TIMEDIR=$backuprootdir/sauvegarde
TAR=/bin/tar
TARCOMMANDS="-cjvvpPf"
LOGFILE=$TIMEDIR/log_file_to_test_tar_parameters.log
echo "" > $LOGFILE
for i in backups billets
do
directory_to_backup="$i"
name_of_the_file=directory_$directory_to_backup
if [ "$directory_to_backup" == "backups" ] ; then
echo "this is the $directory_to_backup" directory >> $LOGFILE
exclude_parameters="computer5-*.tar.bz2,VirtualBox*"
echo "The exclude parameters for directory \"$i\" are : $exclude_parameters" >> $LOGFILE
elif [ "$directory_to_backup" == "billets" ] ; then
echo "this is the $directory_to_backup" directory >> $LOGFILE
exclude_parameters="images_index,assignats.*"
echo "The exclude parameters for directory \"$i\" are : $exclude_parameters" >> $LOGFILE
elif [ "$directory_to_backup" == "tmp" ] ; then
echo "this is the $directory_to_backup" directory >> $LOGFILE
exclude_parameters="tmp/backintime,tmp/jedit_backup_directory"
echo "The exclude parameters for directory \"$i\" are : $exclude_parameters" >> $LOGFILE
else
echo "this is another directory" >> $LOGFILE
exclude_parameters="nothing_to_do-*.tar.bz2" >> $LOGFILE
echo "The exclude parameters for directory \"$i\" are : $exclude_parameters" >> $LOGFILE
fi
echo "$TAR $TARCOMMANDS $name_of_the_file.tar.bz2 $directory_to_backup --exclude={$exclude_parameters}" >> $LOGFILE
cd
cd $backuprootdir
# this works fine :
#$TAR $TARCOMMANDS $name_of_the_file.tar.bz2 $directory_to_backup --exclude={celtes15-*.tar.bz2,VirtualBox*}
# this doesn't work :
$TAR $TARCOMMANDS $name_of_the_file.tar.bz2 $directory_to_backup --exclude="{$exclude_parameters}"
echo "------------------------------------------------------------------------------------------------" >> $LOGFILE
done
exit 1
Я проверил, правильные параметры хорошо передаются в tar, но они не работают, и tar продолжает сохранять каталоги, которые я хочу исключить.