1. 程式人生 > >解壓格式由gzip變為xz腳本

解壓格式由gzip變為xz腳本

stop printf erro 解壓 vat tar lee IT else

#!/bin/bash data_dir="/data2/oss/private-beebank-backup/rds_backup/" damage_dir="/data2/damage_file" bak_dir="/data2/bak_dir" SEND_THREAD_NUM=$1 tmp_fifofile="/tmp/$$.fifo" mkfifo "$tmp_fifofile" exec 6<>"$tmp_fifofile" cd $data_dir for ((i=0;i<$SEND_THREAD_NUM;i++)) do echo done >&6 for sub_dir in `ls $data_dir` do for f in `ls ${sub_dir}` do if [ -f /tmp/stop.txt ];then rm -f /tmp/stop.txt exit 1 fi read -u6 { if [ -f /tmp/stop.txt ];then exit 1 fi sleep 1 file_name=${sub_dir}/$f file_head_name=`echo ${file_name}|cut -d "." -f 1` file_suffix_name=`echo ${file_name}|cut -d "." -f 3` if [[ ${file_suffix_name} == "gz" ]];then tar itf ${file_name} &> /dev/null if [ $? -eq 0 ];then Date=`date +%F_%H:%M:%S` begin_time=`date +%s` before_size=`du -b $file_name|awk ‘{print $1}‘` (dd if=${file_name} && echo ok > /tmp/$f.ddin) |(gunzip && echo ok > /tmp/$f.gunzip)|(xz -z && echo ok > /tmp/$f.xz)|(dd of="${file_head_name}.tar.xz" && echo ok > /tmp/$f.ddout) grep -w ok /tmp/$f.ddin &>/dev/null && grep -w ok /tmp/$f.gunzip &>/dev/null && grep -w ok /tmp/$f.xz &>/dev/null && grep -w ok /tmp/$f.ddout &>/dev/null if [ $? -eq 0 ];then after_size=`du -b "${file_head_name}.tar.xz"|awk ‘{print $1}‘` end_time=`date +%s` conpress_time=`echo |awk -v a=$begin_time -v b=$end_time ‘{printf ("%.2f\n",(b-a)/60)}‘` mv ${file_name} ${bak_dir} echo "$Date ${file_name} before_size: $before_size after_size: $after_size conpress_time: $conpress_time" >> /var/log/gz_to_xz.log #rm -f /tmp/$f.ddin /tmp/$f.gunzip /tmp/$f.xz /tmp/$f.ddout else echo "${file_name} change to xz mode failed" >> /var/log/gz_to_xz_failed.log fi else mv ${file_name} ${damage_dir} echo "${file_name} change to xz mode failed" >> /var/log/gz_to_xz_error.log fi fi echo >&6 }& done done wait exec 6>&- exit 0

解壓格式由gzip變為xz腳本