我有一个bash脚本,基本上读取包含要忽略的文件名的文件并执行rsync命令:
output="sudo rsync -avz"
# Read the file in parameter and fill the array named "array"
getArray() {
i=0
while read line # Read a line
do
output="$output --exclude '$line'"
i=$(($i + 1))
done < $1
}
getArray "/opt/ATP/Webapp/static/ignored_files.txt"
output="$output source/ dest/"
echo $output
echo `$output`
文件列出要忽略的文件
forms.py
forms.pyc
这给了我输出命令
sudo rsync -avz --exclude 'forms.py' --exclude 'forms.pyc' source/ dest/
但是,这只是将源文件夹中的所有文件复制到目标文件,而不会忽略任何文件。如果我在shell中复制并粘贴该行,它将正常工作并忽略文件。
从文件
运行的输出$ sudo sh data_migration.sh
sudo rsync -avz --exclude 'forms.py' --exclude 'forms.pyc' --exclude '' source/ dest/
sending incremental file list ./ __init__.py __init__.pyc admin.py admin.pyc forms.py forms.pyc lists.py lists.pyc models.py models.pyc tables.py urls.py urls.pyc views.py views.pyc wsgi.py
sent 22155 bytes received 319 bytes 44948.00 bytes/sec total size is 60218 speedup is 2.68
目标文件夹的内容
$ ls dest/
admin.py admin.pyc forms.py forms.pyc __init__.py __init__.pyc lists.py lists.pyc models.py models.pyc tables.py urls.py urls.pyc views.py views.pyc wsgi.py
手动投放输出
$ sudo rsync -avz --exclude 'forms.py' --exclude 'forms.pyc' --exclude '' source/ dest/
$ sudo rsync -avz --exclude 'forms.py' --exclude 'forms.pyc' --exclude '' source/ dest/
sending incremental file list
./
__init__.py
__init__.pyc
admin.py
admin.pyc
lists.py
lists.pyc
models.py
models.pyc
tables.py
urls.py
urls.pyc
views.py
views.pyc
wsgi.py
sent 18398 bytes received 281 bytes 37358.00 bytes/sec
total size is 50171 speedup is 2.69