Skip to content

Commit fcd8d61

Browse files
authored
Update rmlocal.script
1 parent d71e421 commit fcd8d61

File tree

1 file changed

+50
-11
lines changed

1 file changed

+50
-11
lines changed

scripts/rmlocal.script

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
. "/usr/bin/config"
88
##############################################################################
99

10+
oldSize=0
11+
movedSize=0
12+
1013
rm_time () {
1114
# Generate filelist and iterate through it...
1215
find "${local_decrypt_dir}" -type f -mtime +$REMOVE_LOCAL_FILES_AFTER_DAYS |
@@ -34,8 +37,22 @@ rm_time () {
3437
done
3538

3639
# Move file to remote destination[s], retaining path
37-
echo "[ $(date $(printenv DATE_FORMAT)) ] Moving file -> ${n} to Google Drive."
3840
rclone move $rclone_options "$@" "$n" "$(printenv RCLONE_CLOUD_ENDPOINT)${destpath}" >/dev/null 2>&1
41+
42+
fileSize=$(du -sb "$n" | awk '{print $1}')
43+
movedSize=$((movedSize + fileSize))
44+
45+
sizeInMb=$((movedSize / 1000 / 1000))
46+
diffSize=$((movedSize - oldSize))
47+
if [[ "${sizeInMb}" -gt 1000 ]]; then
48+
if [[ "${diffSize}" -gt "1000000000" ]]; then # greater than 1 GB
49+
oldSize=$movedSize
50+
echo "[ $(date ${date_format}) ] $((sizeInMb / 1000)) GB uploaded"
51+
fi
52+
elif [[ "${diffSize}" -gt "100000000" ]]; then # greater than 100 MB
53+
oldSize=$movedSize
54+
echo "[ $(date ${date_format}) ] ${sizeInMb} MB uploaded"
55+
fi
3956
done
4057

4158
find "${local_decrypt_dir}" -mindepth 1 -type d -empty -delete
@@ -68,8 +85,22 @@ rm_instant () {
6885
done
6986

7087
# Move file to remote destination[s], retaining path
71-
echo "[ $(date $(printenv DATE_FORMAT)) ] Moving file -> ${n} to Google Drive."
7288
rclone move $rclone_options "$@" "$n" "$(printenv RCLONE_CLOUD_ENDPOINT)${destpath}" >/dev/null 2>&1
89+
90+
fileSize=$(du -sb "$n" | awk '{print $1}')
91+
movedSize=$((movedSize + fileSize))
92+
93+
sizeInMb=$((movedSize / 1000 / 1000))
94+
diffSize=$((movedSize - oldSize))
95+
if [[ "${sizeInMb}" -gt 1000 ]]; then
96+
if [[ "${diffSize}" -gt "1000000000" ]]; then # greater than 1 GB
97+
oldSize=$movedSize
98+
echo "[ $(date ${date_format}) ] $((sizeInMb / 1000)) GB uploaded"
99+
fi
100+
elif [[ "${diffSize}" -gt "100000000" ]]; then # greater than 100 MB
101+
oldSize=$movedSize
102+
echo "[ $(date ${date_format}) ] ${sizeInMb} MB uploaded"
103+
fi
73104
done
74105

75106
find "${local_decrypt_dir}" -mindepth 1 -type d -empty -delete
@@ -83,13 +114,12 @@ rm_space () {
83114
exit 02
84115
fi
85116

86-
addedSpace=0
87117
freeup=$(($FREEUP_ATLEAST_GB * 1000 * 1000 * 1000))
88118

89119
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}' |
90120
while read -r n; do
91-
if [ "$addedSpace" -gt "$freeup" ]; then
92-
spaceInGb=$(($addedSpace / 1000 / 1000 / 1000))
121+
if [ "$movedSize" -gt "$freeup" ]; then
122+
spaceInGb=$(($movedSize / 1000 / 1000 / 1000))
93123
spaceLeft=$(($(du -sb "$local_decrypt_dir" | awk '{print $1}') / 1000 / 1000 / 1000))
94124
echo "[ $(date $(printenv DATE_FORMAT)) ] Removed ${spaceInGb} GB. Media in total ${spaceLeft} GB."
95125
break
@@ -116,14 +146,23 @@ rm_space () {
116146
sleep 10
117147
done
118148

119-
fileSize=$(du -sb "$n" | awk '{print $1}')
120-
addedSpace="$(($addedSpace + $fileSize))"
121-
122-
fileSizeGb=$(($fileSize / 1000 / 1000 / 1000))
123-
124149
# Move file to remote destination[s], retaining path
125-
echo "[ $(date $(printenv DATE_FORMAT)) ] Moving file -> ${n} to Google Drive. Freeing up ${fileSizeGb} GB"
126150
rclone move $rclone_options "$@" "$n" "$(printenv RCLONE_CLOUD_ENDPOINT)${destpath}" >/dev/null 2>&1
151+
152+
fileSize=$(du -sb "$n" | awk '{print $1}')
153+
movedSize=$((movedSize + fileSize))
154+
155+
sizeInMb=$((movedSize / 1000 / 1000))
156+
diffSize=$((movedSize - oldSize))
157+
if [[ "${sizeInMb}" -gt 1000 ]]; then
158+
if [[ "${diffSize}" -gt "1000000000" ]]; then # greater than 1 GB
159+
oldSize=$movedSize
160+
echo "[ $(date ${date_format}) ] $((sizeInMb / 1000)) GB uploaded"
161+
fi
162+
elif [[ "${diffSize}" -gt "100000000" ]]; then # greater than 100 MB
163+
oldSize=$movedSize
164+
echo "[ $(date ${date_format}) ] ${sizeInMb} MB uploaded"
165+
fi
127166
done
128167

129168
find "${local_decrypt_dir}" -mindepth 1 -type d -empty -delete

0 commit comments

Comments
 (0)