#!/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
标签:-%,备份,source,任务,file,var,path,save From: https://www.cnblogs.com/litzhiai/p/17797795.html