Fixing archiver, storing names after deletion

This commit is contained in:
ville rantanen
2016-07-23 16:02:27 +03:00
parent 424ed8c897
commit 1f5214e4aa

View File

@@ -15,7 +15,7 @@ function helpexit() {
exit exit
} }
function listfolders() { function listfolders() {
find "$@" -mindepth $DEPTH -maxdepth $DEPTH -type d | sort | tr '\n' '\000' find "$@" -mindepth $DEPTH -maxdepth $DEPTH -type d | sort
} }
function fsize() { function fsize() {
echo -en "\e[2K\r" echo -en "\e[2K\r"
@@ -27,8 +27,8 @@ function killtrap() {
} }
function exitokay() { function exitokay() {
[[ "$REMOVE" -eq 1 ]] && { exit; } [[ "$REMOVE" -eq 1 ]] && { exit; }
echo -ne "\nIf all looks okay, delete source folders with: # rm -r '" echo -ne "\nIf all looks okay, delete source folders with: # rm -r "
listfolders "${FOLDERS[@]}" | sed -e "s/\x0/' '/g" -e "s,..$,," for folder in "${REALFOLDERS[@]}"; do echo -n "'$folder' "; done
echo '' echo ''
exit exit
} }
@@ -47,6 +47,8 @@ for ((i=1; i<=${#@}; i++)) {
DEPTH=0 DEPTH=0
} }
[[ ${#FOLDERS[@]} -eq 0 ]] && FOLDERS+=( "." ) [[ ${#FOLDERS[@]} -eq 0 ]] && FOLDERS+=( "." )
export IFS=$'\n'
REALFOLDERS=( $( listfolders "${FOLDERS[@]}" ) )
echo 'Existing files will be overwritten!' echo 'Existing files will be overwritten!'
[[ "$REMOVE" -eq 1 ]] && { [[ "$REMOVE" -eq 1 ]] && {
echo 'Source folders will be deleted!' echo 'Source folders will be deleted!'
@@ -58,15 +60,14 @@ echo -n "Archive the following folders "
[[ "$COMPRESSION" -eq 1 ]] && echo -n with gzip compression [[ "$COMPRESSION" -eq 1 ]] && echo -n with gzip compression
} }
echo ':' echo ':'
echo -n "'" for folder in "${REALFOLDERS[@]}"; do echo -n "'$folder', "; done | sed -e "s/..$//"
listfolders "${FOLDERS[@]}" | sed -e "s/\x0/' '/g" -e "s,..$,,"
echo "" echo ""
echo '<ctrl-c> to quit' echo '<ctrl-c> to quit'
read foo read foo
read -a SLEEPS <<< "0.1 0.5 1 2 3 4 5" IFS=" " read -a SLEEPS <<< '0.1 0.5 1 2 3 4 5'
trap killtrap 9 15 trap killtrap 9 15
listfolders "${FOLDERS[@]}" | while read -r -d "" d; do for d in "${REALFOLDERS[@]}"; do
printf "%s" $d printf "%s" $d
tar cvvf "$d.tar" "$d" > "$d.tar.lst" & tar cvvf "$d.tar" "$d" > "$d.tar.lst" &
PID=$! PID=$!
@@ -79,7 +80,7 @@ listfolders "${FOLDERS[@]}" | while read -r -d "" d; do
sleep $i; kill -0 "$PID" &>/dev/null || break 2 sleep $i; kill -0 "$PID" &>/dev/null || break 2
printf . printf .
done done
read -a SLEEPS <<< "4 4 4 4" IFS=" " read -a SLEEPS <<< '4 4 4 4'
done done
fsize "$d.tar" "$DU" fsize "$d.tar" "$DU"
kill -0 "$DUPID" &>/dev/null || kill "$DUPID" &>/dev/null kill -0 "$DUPID" &>/dev/null || kill "$DUPID" &>/dev/null
@@ -102,10 +103,10 @@ trap - 9 15
read foo read foo
} }
echo 'Compressing..' echo 'Compressing..'
read -a SLEEPS <<< "0.1 0.5 1 2 3 4 5" IFS=" " read -a SLEEPS <<< '0.1 0.5 1 2 3 4 5'
trap killtrap 9 15 trap killtrap 9 15
listfolders "${FOLDERS[@]}" | while read -r -d "" d; do for d in "${REALFOLDERS[@]}"; do
DU=$( fastdu -h "$d.tar" ) DU=$( fastdu -h "$d.tar" )
gzip -f "$d.tar" & gzip -f "$d.tar" &
PID=$! PID=$!
@@ -116,7 +117,7 @@ listfolders "${FOLDERS[@]}" | while read -r -d "" d; do
sleep $i; kill -0 "$PID" &>/dev/null || break 2 sleep $i; kill -0 "$PID" &>/dev/null || break 2
printf . printf .
done done
read -a SLEEPS <<< "4 4 4 4" IFS=" " read -a SLEEPS <<< '4 4 4 4'
done done
fsize "$d.tar.gz" "$DU" fsize "$d.tar.gz" "$DU"
echo '' echo ''