2
我有以下目錄結構:焦油使用在bash腳本
/test_dir/logs:
admin-access.log
admin-access.log00001
admin-access.log00002
admin-access.log00003
admin-access.log00004
admin-access.log00005
/test_dir/installer_logs:
AITimeListener.log
installer.log
/test_dir/servers/clust1/logs/:
clust1.out
clust1.out00001
clust1.out00002
clust1.out00003
clust1.out00004
我使用以下命令集的存檔與排除的文件夾:
cd /test_dir/
tar -czhf /backup/test_dir_node01_2016-02-19_initial.tgz --anchored --exclude "logs/*" --exclude "servers/*/logs/*" --exclude "installer_logs/*" *
而作爲結果,我已經得到了壓縮解壓縮後的目錄結構如下:
/backup/logs:
no files here
/backup/installer_logs:
no files here
/backup/servers/clust1/logs/:
no files here
我試圖代碼的bash腳本這是SUP提出做同樣的和沒有運氣, 這裏是我的代碼:
backup.parameters文件:
NC_HOME=/test_dir
BACKUP_HOME=/backup
EXCLUDE_LIST="
--exclude \"logs/*\"
--exclude \"servers/*/logs/*\"
--exclude \"installer_logs/*\"
"
backup_initial.sh文件
#!/bin/bash
if [ ! -f backup.parameters ]; then echo "backup.parameters file not found! exiting...."; exit 1; fi
. ./backup.parameters
TAR_ARGS="czf"
DATE=`date +%F`
HOSTNAME=`hostname`
cd $NC_HOME
echo "Initial backup started on $HOSTNAME at `date \"+%F %T\"`"
tar -czhf $BACKUP_HOME/$(basename $NC_HOME)_"$HOSTNAME"_"$DATE"_initial.tgz --anchored $EXCLUDE_LIST *
echo "Initial backup finished on $HOSTNAME at `date \"+%F %T\"`"
echo "Initial backup location: $BACKUP_HOME/$(basename $NC_HOME)_"$HOSTNAME"_"$DATE"_initial.tgz"
存檔的解壓縮後這是由腳本創建我看到仍然有排除目錄中的文件:
/backup/logs:
admin-access.log
admin-access.log00001
admin-access.log00002
admin-access.log00003
admin-access.log00004
admin-access.log00005
/backup/installer_logs:
AITimeListener.log
installer.log
/backup/servers/clust1/logs/:
clust1.out
clust1.out00001
clust1.out00002
clust1.out00003
clust1.out00004
請幫助我如何編碼出來,也請不要建議我使用-X選項。 我真的需要用--exclude來做。
它的工作原理!非常感謝你 – cubatura