备份任务

#!/bin/bash
###############################################################################
# 压缩文件脚本
# source_path  : 要压缩的路径  如: /data/file/
# extension : 要压缩的文件类型, 如 .log  .class
# save_path : 要保存的路径 如: /data/file/backup/
###############################################################################

#extension=$1
#source_path=$2
source_path=/islion_all/data/xiaoneng/jiake/dbbackup-new
save_path=/islion_all/data/xiaoneng/jiake/DBBackup_zip

if [ ! -d "${source_path}" ]; then
    echo "[$(date +%Y-%m-%d\ %H:%M:%S)]-路径不存在,退出!"
    exit 0
fi

if [ ! -d "${save_path}" ]; then
    mkdir -p ${save_path}
fi

array_file=$(ls ${source_path} -1)
for var_file in ${array_file}; do
    temp=$(echo ${var_file} | awk -F "[/]" '{print $(NF)}')
    echo "[$(date +%Y-%m-%d\ %H:%M:%S)]-将[${var_file}]压缩为 [${save_path}/${temp}.tar]!"
    #tar -zcvPf  ${save_path}${temp}.tar ${var_file}
    7za a ${save_path}/${temp}.7z  ${source_path}/${var_file}
    rm -rf ${source_path}/${var_file}
done

 

posted @ 2023-10-30 14:24  大川哥  阅读(6)  评论(0编辑  收藏  举报