removal for archival
This commit is contained in:
@@ -8,6 +8,7 @@ function helpexit() {
|
|||||||
echo "Usage: $BS [-z/-n] [folder name(s)]"
|
echo "Usage: $BS [-z/-n] [folder name(s)]"
|
||||||
echo " -z Compress. If not given, will ask action after archiving"
|
echo " -z Compress. If not given, will ask action after archiving"
|
||||||
echo " -n No compression. Exit after TARchive"
|
echo " -n No compression. Exit after TARchive"
|
||||||
|
echo " --rm Remove source folders after archival"
|
||||||
echo " folder name: If given, archive only the named folder(s)."
|
echo " folder name: If given, archive only the named folder(s)."
|
||||||
echo " If not, for loop over all folders in the current directory."
|
echo " If not, for loop over all folders in the current directory."
|
||||||
|
|
||||||
@@ -33,11 +34,13 @@ function exitokay() {
|
|||||||
|
|
||||||
DEPTH=1
|
DEPTH=1
|
||||||
FOLDERS=( )
|
FOLDERS=( )
|
||||||
|
REMOVE=0
|
||||||
for ((i=1; i<=${#@}; i++)) {
|
for ((i=1; i<=${#@}; i++)) {
|
||||||
[[ "${!i}" = "-h" ]] && helpexit
|
[[ "${!i}" = "-h" ]] && helpexit
|
||||||
[[ "${!i}" = "--help" ]] && helpexit
|
[[ "${!i}" = "--help" ]] && helpexit
|
||||||
[[ "${!i}" = "-n" ]] && { NOCOMPRESSION=1; continue; }
|
[[ "${!i}" = "-n" ]] && { NOCOMPRESSION=1; continue; }
|
||||||
[[ "${!i}" = "-z" ]] && { COMPRESSION=1; continue; }
|
[[ "${!i}" = "-z" ]] && { COMPRESSION=1; continue; }
|
||||||
|
[[ "${!i}" = "--rm" ]] && { REMOVE=1; continue; }
|
||||||
[[ "${!i}" = "-"* ]] && helpexit
|
[[ "${!i}" = "-"* ]] && helpexit
|
||||||
FOLDERS+=( "${!i%/}" )
|
FOLDERS+=( "${!i%/}" )
|
||||||
DEPTH=0
|
DEPTH=0
|
||||||
@@ -77,6 +80,14 @@ listfolders "${FOLDERS[@]}" | while read -r -d "" d; do
|
|||||||
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
|
||||||
echo ''
|
echo ''
|
||||||
|
if wait $PID; then
|
||||||
|
# tar exists okay
|
||||||
|
[[ "$REMOVE" -eq 1 ]] && {
|
||||||
|
echo Removing folder $d
|
||||||
|
which rm-progress &> /dev/null && rm-progress -f "$d"
|
||||||
|
[[ -d "$d" ]] && rm -r "$d"
|
||||||
|
}
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
trap - 9 15
|
trap - 9 15
|
||||||
[[ "$NOCOMPRESSION" -eq 1 ]] && {
|
[[ "$NOCOMPRESSION" -eq 1 ]] && {
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ function deletefolders() {
|
|||||||
percent=$((200*$i/$folders % 2 + 100*$i/$folders))
|
percent=$((200*$i/$folders % 2 + 100*$i/$folders))
|
||||||
printf "\r%02d:%02d:%02d %6d/%d %3d%% %s\033[0K" \
|
printf "\r%02d:%02d:%02d %6d/%d %3d%% %s\033[0K" \
|
||||||
$(($SECONDS/3600)) $(($SECONDS%3600/60)) $(($SECONDS%60)) $i $folders $percent "$line"
|
$(($SECONDS/3600)) $(($SECONDS%3600/60)) $(($SECONDS%60)) $i $folders $percent "$line"
|
||||||
rm -rf "$line"
|
rm -r "$line"
|
||||||
done < <(find "$@" -depth -type d -print0)
|
done < <(find "$@" -depth -type d -print0)
|
||||||
printf "\n"
|
printf "\n"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user