标签:href bash 标准 鄙视 sqlite ext ace variable rem
异地
备份一轮,脚本如下:#!/bin/bash
# Copy.sh : Backup the files to remote storage.
readonly pDir="${1:-~/XiaoMi/Image/}" # 照片文件备份路径
readonly vDir="${2:-~/XiaoMi/Video/}" # 视频文件备份路径
readonly dDir="${3:-~/XiaoMi/Document/}" # 日志存储目录
readonly iLog="${dDir}Copy.log" # 备份成功
readonly wLog="${dDir}Copy.wan" # 已经存在
readonly eLog="${dDir}Copy.err" # 无需备份和出错信息
readonly debug=false # 调试开关,按需开启
readonly stdName="(^|[[:space:]])[2,1][0,9][0,1,2,7,9][0-9][0-1][0-9][0-3][0-9]-[0-2][0-9][0-5][0-9][0-5][0-9]($|[[:space:]])" # 标准格式
find ~{higkoo,anglix}/Drive/{Moments,Backup} ! -path "*@eaDir*" -type f | while read -r sPath; do
unset fName sExt rCopy rCode nDir dPath
sExt="${sPath##*.}" && sExt="${sExt,,}"
[[ ${sExt} == "jpeg" ]] && sExt=‘jpg‘ # 将jpeg后缀改为jpg
fName="${sPath##*/}" && fName="${fName%%.*}"
if [[ $fName =~ $stdName ]]; then # 识别文件名
case $sExt in
jpg | livp | heic | cr2 )
nDir="${pDir}${fName:0:4}/"
rCopy=true && rCode=‘+‘
;;
mp4 | mov | m4v | wmv )
nDir="${vDir}${fName:0:4}/"
rCopy=true && rCode=‘-‘
;;
png | * ) # 鄙视 png ,全是截图
rCopy=false && rCode=‘*‘
;;
esac
else
rCopy=false && rCode=‘/‘
fi
if [[ $rCopy && ! -z ${nDir} ]]; then
dPath="${nDir}${fName}.${sExt}"
if [[ ! -f "${dPath}" || `stat --printf=%s "${dPath}" 2>/dev/null` -lt `stat --printf=%s "${sPath}"` ]]; then
mkdir -pv "${nDir}" >> ${wLog}
cp -v "${sPath}" "${dPath}" >>${iLog} 2>>${eLog}
else
echo "$sPath" >> ${wLog} && rCode=‘^‘
fi
else
echo "$sPath" >> ${eLog}
fi
echo -ne "$rCode"
$debug && declare -p sPath dPath && exit 0
done
exiv2
重命名后备份过一次,所以不少^
以示逃过。+
代表收获1张新照片,-
代表收获1张新视频,/
是不必备份的文件。标签:href bash 标准 鄙视 sqlite ext ace variable rem
原文地址:https://www.cnblogs.com/1994july/p/12438843.html