diff --git a/rclone.sh b/rclone.sh index d6e0232..070ae48 100755 --- a/rclone.sh +++ b/rclone.sh @@ -26,15 +26,17 @@ function gzipVMbackups { # loop through VM backups and tar/gzip them to single file for dir in /mnt/data-pool/esxi/backups/*/*/; do - # get the folder name of the backup - base=$(basename "${dir}") - # had to cd into the directoy since tar -C $dir was not working for me with relative path - cd ${dir%/*/} - # create the tar and pipe into pigz for multi-threaded gzip - tar cf - "${base}" | pigz > "${dir%/}.gz" - # if the tar/gzip was successful, delete the backup directory - if [ $? -eq 0 ] && [ -f "${dir%/}.gz" ]; then - rm -rf "${dir}" + if [ ! -z "$dir" ]; + # get the folder name of the backup + base=$(basename "${dir}") + # had to cd into the directoy since tar -C $dir was not working for me with relative path + cd "${dir%/*/}" + # create the tar and pipe into pigz for multi-threaded gzip + tar cf - "${base}" | pigz > "${dir%/}.gz" + # if the tar/gzip was successful, delete the backup directory + if [ $? -eq 0 ] && [ -f "${dir%/}.gz" ]; then + rm -rf "${dir}" + fi fi done }