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