call it file-version instead

This commit is contained in:
2018-07-10 11:19:52 +03:00
parent 162c10e846
commit 8ba01c110b
3 changed files with 75 additions and 27 deletions

View File

@@ -9,17 +9,18 @@ function helpexit() {
echo "Usage: $BS [-z/-n/--rm] [folder name(s)]"
echo " -z Compress."
echo " -n No compression. [default]"
echo " --rm Remove source folders after archival"
echo " --nl Do not store a separate file list."
echo " --rm Remove source folders after archival."
echo " folder name: If given, archive only the named folder(s)."
echo " If not, for loop over all folders in the current directory."
exit
}
function listfolders() {
find "$@" -mindepth $DEPTH -maxdepth $DEPTH -type d | sort
find "$@" -mindepth $DEPTH -maxdepth $DEPTH -type d | sort
}
function count_size() {
cat - | python -c "import sys
def sizeof_fmt(num, suffix='B'):
for unit in ['','K','M','G','T','P','E','Z']:
@@ -42,11 +43,11 @@ print(sum)
}
function exitokay() {
[[ "$REMOVE" -eq 1 ]] && { exit; }
[[ "$REMOVE" -eq 1 ]] && { exit; }
echo -ne "\n${G}If all looks okay, delete source folders with: ${Z}# rm -r "
for folder in "${REALFOLDERS[@]}"; do echo -n "'$folder' "; done
for folder in "${REALFOLDERS[@]}"; do echo -n "'$folder' "; done
echo ''
exit
exit
}
_qCol(){ true; } # incase qolop missing
@@ -63,41 +64,47 @@ SUFFIX=tar
DEPTH=1
FOLDERS=( )
REMOVE=0
KEEP_LIST=1
for ((i=1; i<=${#@}; i++)) {
[[ "${!i}" = "-h" ]] && helpexit
[[ "${!i}" = "--help" ]] && helpexit
[[ "${!i}" = "-n" ]] && { continue; } # obsolete behaviour
[[ "${!i}" = "-z" ]] && { COMPRESSION=1; NOCOMPRESSION=0; COMPRESSCMD="| gzip"; SUFFIX=tgz; continue; }
[[ "${!i}" = "--nl" ]] && { KEEP_LIST=0; continue; }
[[ "${!i}" = "--rm" ]] && { REMOVE=1; continue; }
[[ "${!i}" = "-"* ]] && helpexit
FOLDERS+=( "${!i%/}" )
DEPTH=0
}
[[ ${#FOLDERS[@]} -eq 0 ]] && FOLDERS+=( "." )
which pv &>/dev/null || { echo pv command missing; exit 1; }
which pv &>/dev/null || { echo pv command missing; exit 1; }
export IFS=$'\n'
REALFOLDERS=( $( listfolders "${FOLDERS[@]}" ) )
echo $R'Existing files will be overwritten!'$Z
[[ "$REMOVE" -eq 1 ]] && echo 'Source folders will be deleted!'
[[ "$REMOVE" -eq 1 ]] && echo 'Source folders will be deleted!'
[[ "$KEEP_LIST" -eq 0 ]] && echo 'File list will be removed.'
echo -n $S"Archive the following folders "
[[ "$NOCOMPRESSION" -eq 1 ]] && {
echo -n without compression;
} || {
[[ "$NOCOMPRESSION" -eq 1 ]] && {
echo -n without compression;
} || {
[[ "$COMPRESSION" -eq 1 ]] && echo -n with gzip compression
}
echo ':'$Z
for folder in "${REALFOLDERS[@]}"; do echo -n "'$folder', "; done | sed -e "s/..$//"
for folder in "${REALFOLDERS[@]}"; do echo -n "'$folder', "; done | sed -e "s/..$//"
printf "\n$S<ctrl-c> to quit$Z\n"
read foo
set -o pipefail
for d in "${REALFOLDERS[@]}"; do
for d in "${REALFOLDERS[@]}"; do
printf "$d"
SIZE=$( find "$d" -type f -printf %s"\n" | count_size "$d" )
printf "\n"
eval "tar cvv --index-file=\"$d.${SUFFIX}.lst\" \"$d\" | \
pv -s \"$SIZE\" $COMPRESSCMD > \"$d.${SUFFIX}\"" && {
# tar exists okay
if [ "$KEEP_LIST" -eq 0 ]; then
rm -f "$d.${SUFFIX}.lst"
fi
if [ "$REMOVE" -eq 1 ]; then
printf "${Y}Removing folder $d$Z\n"
which rm-progress &> /dev/null && rm-progress -f "$d"