rsync 迁移文件夹到指定文件夹 2023-07-13
2023-07-12 本文已影响0人
阿然学编程
- 新建shell脚本:
qianyi.sh
#!/bin/bash
# 设置迁移的源文件夹的路径
SOURCE_FOLDER="/www/wwwroot/test01"
# 设置要迁移到目标文件夹的路径
DESTINATION_FOLDER="/www/wwwroot/test02"
# 是否压缩传输
IS_AVZ=true
# 设置要跳过的文件和文件夹
SKIP_DIRS=("log" "cache") # 要跳过的文件夹名称列表
SKIP_EXT=(".log" ".tmp") # 要跳过的文件扩展名列表
EXCLUDE_DIRS=""
for dir in "${SKIP_DIRS[@]}"; do
EXCLUDE_DIRS+="--exclude='$dir' "
done
EXCLUDE_EXT=""
for ext in "${SKIP_EXT[@]}"; do
EXCLUDE_EXT+="--exclude='*$ext' "
done
mkdir -p ${DESTINATION_FOLDER}
if [[ ${IS_AVZ} == true ]]; then
rsync -avzP --delete --progress --ignore-existing ${EXCLUDE_DIRS} ${EXCLUDE_EXT} "${SOURCE_FOLDER}/" ${DESTINATION_FOLDER}
else
rsync -avhP --delete --progress --ignore-existing ${EXCLUDE_DIRS} ${EXCLUDE_EXT} "${SOURCE_FOLDER}/" ${DESTINATION_FOLDER}
fi
echo "迁移完成"
exit
- 执行脚本
./qianyi.sh