bash : archive : change archive ext to tgz and txz.
This commit is contained in:
parent
8ff59d23c6
commit
b952ea0583
|
@ -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"
|
alias _ARCHIVE_DATE="date +%Y%m%d%H%M"
|
||||||
|
|
||||||
# archive file with maximum compression and checksum.
|
# archive file with maximum compression and checksum.
|
||||||
|
@ -26,10 +26,10 @@ archive()
|
||||||
echo "${status}"
|
echo "${status}"
|
||||||
|
|
||||||
# create archive.
|
# 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.
|
# 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.
|
# report success.
|
||||||
echo -e "${color_green}${status}: done.${color_default}"
|
echo -e "${color_green}${status}: done.${color_default}"
|
||||||
|
@ -61,10 +61,10 @@ archive_fast()
|
||||||
echo "${status}"
|
echo "${status}"
|
||||||
|
|
||||||
# create archive.
|
# 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.
|
# 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.
|
# report success.
|
||||||
echo -e "${color_green}${status}: done.${color_default}"
|
echo -e "${color_green}${status}: done.${color_default}"
|
||||||
|
@ -239,6 +239,7 @@ archive_convert()
|
||||||
local old_format="_[[:alnum:]]{40}.tar.[xg]z"
|
local old_format="_[[:alnum:]]{40}.tar.[xg]z"
|
||||||
local targets=($(ls | grep -E ${old_format}))
|
local targets=($(ls | grep -E ${old_format}))
|
||||||
|
|
||||||
|
# add timestamp.
|
||||||
for target in "${targets[@]}"; do
|
for target in "${targets[@]}"; do
|
||||||
local stamp=$(stat --format '%w' -- "${target}" | sed -e 's/\..*//' -e 's/:..$//' -e 's/-//g' -e 's/://' -e 's/\ //')
|
local stamp=$(stat --format '%w' -- "${target}" | sed -e 's/\..*//' -e 's/:..$//' -e 's/-//g' -e 's/://' -e 's/\ //')
|
||||||
local name="${target%_*}"
|
local name="${target%_*}"
|
||||||
|
@ -249,6 +250,30 @@ archive_convert()
|
||||||
|
|
||||||
mv "${target}" "${new_name}"
|
mv "${target}" "${new_name}"
|
||||||
done
|
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..
|
# export everything, primarily for use with parallel..
|
||||||
|
|
Reference in a new issue