functionworkdir (){ if [ ! -d "$1" ]; then mkdir -p "$1"; fi }
functionbackup (){ for dir in${!BACKUP_LIST[*]} do _dirlist+=${dir}" " for exc in${BACKUP_LIST[${dir}]}; do _exclist+="--exclude=${dir}/${exc} "; done done for file in${EXCFILE}; do _exclist+="--exclude=*${file} "; done echo"$(date) 正在备份数据, 请等待..." echo"$(date) tar -zcPf ${FileTGZ}${_exclist}${_dirlist}" sudo tar -zcPf ${FileTGZ}${_exclist}${_dirlist} if [ $? -eq 0 ]; then echo"$(date) 备份成功: ${FileTGZ}" else echo"$(date) 备份失败, 原因未知" fi }
functiondelete (){ echo"$(date) 历史备份数据删除前检查..." sleep 2 count=$(find $1 -name "Data-*${FileType}" |sort |wc -l) if [ $count -gt $2 ]; then dellist=$(find $1 -name "Data-*${FileType}" |sort |head -n $(expr ${count} - $2)) for tgz in${dellist}; do rm -f $tgz; done echo"$(date) 删除文件: $dellist " else echo"$(date) 未满足删除条件" fi }