Skip to content

Commit

Permalink
Update rmlocal.script
Browse files Browse the repository at this point in the history
  • Loading branch information
madslundt authored Jan 17, 2018
1 parent d71e421 commit fcd8d61
Showing 1 changed file with 50 additions and 11 deletions.
61 changes: 50 additions & 11 deletions scripts/rmlocal.script
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit fcd8d61

Please sign in to comment.