From fcd8d61c2315ec273446c61c05fc5f2337cf2d46 Mon Sep 17 00:00:00 2001 From: Mads Lundt Date: Wed, 17 Jan 2018 21:02:50 +0100 Subject: [PATCH] Update rmlocal.script --- scripts/rmlocal.script | 61 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 11 deletions(-) diff --git a/scripts/rmlocal.script b/scripts/rmlocal.script index c898565..c4838cd 100755 --- a/scripts/rmlocal.script +++ b/scripts/rmlocal.script @@ -7,6 +7,9 @@ . "/usr/bin/config" ############################################################################## +oldSize=0 +movedSize=0 + rm_time () { # Generate filelist and iterate through it... find "${local_decrypt_dir}" -type f -mtime +$REMOVE_LOCAL_FILES_AFTER_DAYS | @@ -34,8 +37,22 @@ rm_time () { done # Move file to remote destination[s], retaining path - echo "[ $(date $(printenv DATE_FORMAT)) ] Moving file -> ${n} to Google Drive." rclone move $rclone_options "$@" "$n" "$(printenv RCLONE_CLOUD_ENDPOINT)${destpath}" >/dev/null 2>&1 + + fileSize=$(du -sb "$n" | awk '{print $1}') + movedSize=$((movedSize + fileSize)) + + sizeInMb=$((movedSize / 1000 / 1000)) + diffSize=$((movedSize - oldSize)) + if [[ "${sizeInMb}" -gt 1000 ]]; then + if [[ "${diffSize}" -gt "1000000000" ]]; then # greater than 1 GB + oldSize=$movedSize + echo "[ $(date ${date_format}) ] $((sizeInMb / 1000)) GB uploaded" + fi + elif [[ "${diffSize}" -gt "100000000" ]]; then # greater than 100 MB + oldSize=$movedSize + echo "[ $(date ${date_format}) ] ${sizeInMb} MB uploaded" + fi done find "${local_decrypt_dir}" -mindepth 1 -type d -empty -delete @@ -68,8 +85,22 @@ rm_instant () { done # Move file to remote destination[s], retaining path - echo "[ $(date $(printenv DATE_FORMAT)) ] Moving file -> ${n} to Google Drive." rclone move $rclone_options "$@" "$n" "$(printenv RCLONE_CLOUD_ENDPOINT)${destpath}" >/dev/null 2>&1 + + fileSize=$(du -sb "$n" | awk '{print $1}') + movedSize=$((movedSize + fileSize)) + + sizeInMb=$((movedSize / 1000 / 1000)) + diffSize=$((movedSize - oldSize)) + if [[ "${sizeInMb}" -gt 1000 ]]; then + if [[ "${diffSize}" -gt "1000000000" ]]; then # greater than 1 GB + oldSize=$movedSize + echo "[ $(date ${date_format}) ] $((sizeInMb / 1000)) GB uploaded" + fi + elif [[ "${diffSize}" -gt "100000000" ]]; then # greater than 100 MB + oldSize=$movedSize + echo "[ $(date ${date_format}) ] ${sizeInMb} MB uploaded" + fi done find "${local_decrypt_dir}" -mindepth 1 -type d -empty -delete @@ -83,13 +114,12 @@ rm_space () { exit 02 fi - addedSpace=0 freeup=$(($FREEUP_ATLEAST_GB * 1000 * 1000 * 1000)) find "${local_decrypt_dir}" -type f -print0 | xargs -0 stat --format '%Y :%y %n' | sort -n | cut -d: -f2- | awk '{$1=$2=$3=""; print $0}' | while read -r n; do - if [ "$addedSpace" -gt "$freeup" ]; then - spaceInGb=$(($addedSpace / 1000 / 1000 / 1000)) + if [ "$movedSize" -gt "$freeup" ]; then + spaceInGb=$(($movedSize / 1000 / 1000 / 1000)) spaceLeft=$(($(du -sb "$local_decrypt_dir" | awk '{print $1}') / 1000 / 1000 / 1000)) echo "[ $(date $(printenv DATE_FORMAT)) ] Removed ${spaceInGb} GB. Media in total ${spaceLeft} GB." break @@ -116,14 +146,23 @@ rm_space () { sleep 10 done - fileSize=$(du -sb "$n" | awk '{print $1}') - addedSpace="$(($addedSpace + $fileSize))" - - fileSizeGb=$(($fileSize / 1000 / 1000 / 1000)) - # Move file to remote destination[s], retaining path - echo "[ $(date $(printenv DATE_FORMAT)) ] Moving file -> ${n} to Google Drive. Freeing up ${fileSizeGb} GB" rclone move $rclone_options "$@" "$n" "$(printenv RCLONE_CLOUD_ENDPOINT)${destpath}" >/dev/null 2>&1 + + fileSize=$(du -sb "$n" | awk '{print $1}') + movedSize=$((movedSize + fileSize)) + + sizeInMb=$((movedSize / 1000 / 1000)) + diffSize=$((movedSize - oldSize)) + if [[ "${sizeInMb}" -gt 1000 ]]; then + if [[ "${diffSize}" -gt "1000000000" ]]; then # greater than 1 GB + oldSize=$movedSize + echo "[ $(date ${date_format}) ] $((sizeInMb / 1000)) GB uploaded" + fi + elif [[ "${diffSize}" -gt "100000000" ]]; then # greater than 100 MB + oldSize=$movedSize + echo "[ $(date ${date_format}) ] ${sizeInMb} MB uploaded" + fi done find "${local_decrypt_dir}" -mindepth 1 -type d -empty -delete