From b952ea0583ecea5419a6265c19d6d36b4f1deb88 Mon Sep 17 00:00:00 2001 From: home Date: Thu, 2 Nov 2023 21:49:26 +0300 Subject: [PATCH] bash : archive : change archive ext to tgz and txz. --- .linux/bash/module/archive.sh | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/.linux/bash/module/archive.sh b/.linux/bash/module/archive.sh index 1dbbde2..1faaa05 100644 --- a/.linux/bash/module/archive.sh +++ b/.linux/bash/module/archive.sh @@ -1,4 +1,4 @@ -_ARCHIVE_PATTERN="_[0-9]{12}-[[:alnum:]]{40}.tar.[xg]z" +_ARCHIVE_PATTERN="_[0-9]{12}-[[:alnum:]]{40}.t[xg]z" alias _ARCHIVE_DATE="date +%Y%m%d%H%M" # archive file with maximum compression and checksum. @@ -26,10 +26,10 @@ archive() echo "${status}" # create archive. - tar -c "${target}" | pv -s $(du -sb "${target}" | awk '{print $1}') | xz -9e > "${target%/*}".tar.xz + tar -c "${target}" | pv -s $(du -sb "${target}" | awk '{print $1}') | xz -9e > "${target%/*}".txz # append hash to target name. - mv "${target%/*}".tar.xz "${target%/*}"_${date}-$(sha1sum "${target%/*}".tar.xz | cut -d\ -f1).tar.xz + mv "${target%/*}".txz "${target%/*}"_${date}-$(sha1sum "${target%/*}".txz | cut -d\ -f1).txz # report success. echo -e "${color_green}${status}: done.${color_default}" @@ -61,10 +61,10 @@ archive_fast() echo "${status}" # create archive. - tar -c "${target}" | pv -s $(du -sb "${target}" | awk '{print $1}') | gzip -1 > "${target%/*}".tar.gz + tar -c "${target}" | pv -s $(du -sb "${target}" | awk '{print $1}') | gzip -1 > "${target%/*}".tgz # append hash to target name. - mv "${target%/*}".tar.gz "${target%/*}"_${date}-$(sha1sum "${target%/*}".tar.gz | cut -d\ -f1).tar.gz + mv "${target%/*}".tgz "${target%/*}"_${date}-$(sha1sum "${target%/*}".tgz | cut -d\ -f1).tgz # report success. echo -e "${color_green}${status}: done.${color_default}" @@ -239,6 +239,7 @@ archive_convert() local old_format="_[[:alnum:]]{40}.tar.[xg]z" local targets=($(ls | grep -E ${old_format})) + # add timestamp. for target in "${targets[@]}"; do local stamp=$(stat --format '%w' -- "${target}" | sed -e 's/\..*//' -e 's/:..$//' -e 's/-//g' -e 's/://' -e 's/\ //') local name="${target%_*}" @@ -249,6 +250,30 @@ archive_convert() mv "${target}" "${new_name}" done + + # convert tar.xz and tar.gz to .tgz and .txz. + old_format="_[0-9]{12}-[[:alnum:]]{40}.tar.[xg]z" + targets=($(ls | grep -E ${old_format})) + + for target in "${targets[@]}"; do + local compression="${target##*.}" + local new_compression + + case "${compression}" in + "gz") + new_compression="tgz" + ;; + "xz") + new_compression="txz" + ;; + esac + + local new_name="${target%.tar.*}".${new_compression} + + echo "${target} -> ${new_name}" + + mv -- "${target}" "${new_name}" + done } # export everything, primarily for use with parallel..