archive : fix prune.
This commit is contained in:
parent
4f68139a17
commit
f4f1a0664e
|
@ -11,6 +11,7 @@ archive()
|
||||||
local IFS=$'\n'
|
local IFS=$'\n'
|
||||||
local targets=("${@}") # target file(s).
|
local targets=("${@}") # target file(s).
|
||||||
local count=0 # processed count.
|
local count=0 # processed count.
|
||||||
|
local failed=0
|
||||||
local total=${#} # total to process.
|
local total=${#} # total to process.
|
||||||
local date=$(_ARCHIVE_DATE) # date stamp.
|
local date=$(_ARCHIVE_DATE) # date stamp.
|
||||||
|
|
||||||
|
@ -30,13 +31,17 @@ archive()
|
||||||
echo -e "${status}"
|
echo -e "${status}"
|
||||||
|
|
||||||
# create archive.
|
# create archive.
|
||||||
tar -c "${target}" | pv -s $(du -sb "${target}" | awk '{print $1}') | xz -9e > "${target%/*}".txz
|
tar -c "${target}" | pv -s $(du -sb "${target}" | awk '{print $1}') | xz -9e > "${target%/*}".txz || ((failed++))
|
||||||
|
|
||||||
# append hash to target name.
|
# append hash to target name.
|
||||||
mv "${target%/*}".txz "${target%/*}"_${date}-$(pv "${target%/*}".txz | sha1sum | cut -d\ -f1).txz
|
mv "${target%/*}".txz "${target%/*}"_${date}-$(pv "${target%/*}".txz | sha1sum | cut -d\ -f1).txz || ((failed++))
|
||||||
|
|
||||||
# report success.
|
# report success.
|
||||||
|
if [[ ${failed} = 0 ]]; then
|
||||||
echo -e "${color_green}${status}: Done.${color_default}"
|
echo -e "${color_green}${status}: Done.${color_default}"
|
||||||
|
else
|
||||||
|
echo -e "${color_bred}${status}: Failed.${color_default}"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,6 +52,7 @@ archive_fast()
|
||||||
local IFS=$'\n'
|
local IFS=$'\n'
|
||||||
local targets=("${@}") # target file(s).
|
local targets=("${@}") # target file(s).
|
||||||
local count=0 # processed count.
|
local count=0 # processed count.
|
||||||
|
local failed=0
|
||||||
local total=${#} # total to process.
|
local total=${#} # total to process.
|
||||||
local date=$(_ARCHIVE_DATE) # date stamp.
|
local date=$(_ARCHIVE_DATE) # date stamp.
|
||||||
|
|
||||||
|
@ -66,13 +72,17 @@ archive_fast()
|
||||||
echo -e "${status}"
|
echo -e "${status}"
|
||||||
|
|
||||||
# create archive.
|
# create archive.
|
||||||
tar -c "${target}" | pv -s $(du -sb "${target}" | awk '{print $1}') | gzip -1 > "${target%/*}".tgz
|
tar -c "${target}" | pv -s $(du -sb "${target}" | awk '{print $1}') | gzip -1 > "${target%/*}".tgz || ((failed++))
|
||||||
|
|
||||||
# append hash to target name.
|
# append hash to target name.
|
||||||
mv "${target%/*}".tgz "${target%/*}"_${date}-$(pv "${target%/*}".tgz | sha1sum | cut -d\ -f1).tgz
|
mv "${target%/*}".tgz "${target%/*}"_${date}-$(pv "${target%/*}".tgz | sha1sum | cut -d\ -f1).tgz || ((failed++))
|
||||||
|
|
||||||
# report success.
|
# report success.
|
||||||
|
if [[ ${failed} = 0 ]]; then
|
||||||
echo -e "${color_green}${status}: Done.${color_default}"
|
echo -e "${color_green}${status}: Done.${color_default}"
|
||||||
|
else
|
||||||
|
echo -e "${color_bred}${status}: Failed.${color_default}"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,25 +144,46 @@ archive_prune()
|
||||||
local IFS=$'\n'
|
local IFS=$'\n'
|
||||||
local targets=("${@}")
|
local targets=("${@}")
|
||||||
local count=0
|
local count=0
|
||||||
|
local failed=0
|
||||||
local total=${#}
|
local total=${#}
|
||||||
|
|
||||||
# All archives by default.
|
# All archives by default.
|
||||||
if [[ "${target}" = "" ]]; then
|
if [[ "${targets}" = "" ]]; then
|
||||||
targets=($(ls | grep -E ${_ARCHIVE_PATTERN}))
|
targets=($(ls | grep -E ${_ARCHIVE_PATTERN}))
|
||||||
total=${#targets[@]}
|
total=${#targets[@]}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Iterate each target.
|
# Iterate each target.
|
||||||
for target in "${targets[@]}"; do
|
for target in "${targets[@]}"; do
|
||||||
# Only work with files.
|
# Only work with existing files.
|
||||||
[[ -f "${target}" ]] || continue
|
[[ -f "${target}" ]] || continue
|
||||||
|
|
||||||
# Iterate counter.
|
# Iterate counter.
|
||||||
((count++))
|
((count++))
|
||||||
|
|
||||||
local name="${target%_*}"
|
local name="${target%_*}"
|
||||||
# local copies=("$()")
|
local data="${target##*_}"
|
||||||
|
local time="${data%%-*}"
|
||||||
|
local copies=($(ls ${name}_*))
|
||||||
|
|
||||||
|
# Iterate each copy.
|
||||||
|
for copy in "${copies[@]}"; do
|
||||||
|
local copy_data="${copy##*_}"
|
||||||
|
local copy_time="${copy_data%%-*}"
|
||||||
|
|
||||||
|
if [[ "${copy_time}" -lt "${time}" ]]; then
|
||||||
|
echo -e "${name}: prune ${copy_time}."
|
||||||
|
rm -- "${copy}" || ((failed++))
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
# Report result.
|
||||||
|
if [[ ${failed} = 0 ]]; then
|
||||||
|
echo -e "${color_green}All successful.${color_default}"
|
||||||
|
else
|
||||||
|
echo -e "${color_bred}Items failed to prune: ${failed}.${color_default}"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# extract previously created archive with checksum validation.
|
# extract previously created archive with checksum validation.
|
||||||
|
|
Reference in a new issue