Skip to content

Commit 6bfdf3e

Browse files
committed
Added option to remove files instant
1 parent d5826b5 commit 6bfdf3e

File tree

4 files changed

+45
-7
lines changed

4 files changed

+45
-7
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ Environment variables:
6464
* `-e CLEAR_CHUNK_AGE` - Plexdrive: The maximum age of a cached chunk file (default **24h**) - this is ignored if `CLEAR_CHUNK_MAX_SIZE` is set
6565
* `-e MONGO_DATABASE` - Mongo database used for Plexdrive (default **plexdrive**)
6666
* `-e DATE_FORMAT` - Date format for loggin (default **+%F@%T**)
67-
* `-e REMOVE_LOCAL_FILES_BASED_ON` - Remove local files based on `space` or `time` (default **space**)
68-
* `-e REMOVE_LOCAL_FILES_WHEN_SPACE_EXCEEDS_GB` - Remove local files when local storage exceeds this value in GB (default **100**) - this is ignored if `REMOVE_LOCAL_FILES_BASED_ON` is set to time
69-
* `-e FREEUP_ATLEAST_GB` - Remove atleast this value in GB on removal (default **80**) - this is ignored if `REMOVE_LOCAL_FILES_BASED_ON` is set to time
70-
* `-e REMOVE_LOCAL_FILES_AFTER_DAYS` Remove local files older than this value in days (default **10**) - this is ignored if `REMOVE_LOCAL_FILES_BASED_ON` is set to space
67+
* `-e REMOVE_LOCAL_FILES_BASED_ON` - Remove local files based on `space`, `time` or `instant` (default **space**)
68+
* `-e REMOVE_LOCAL_FILES_WHEN_SPACE_EXCEEDS_GB` - Remove local files when local storage exceeds this value in GB (default **100**) - this is ignored if `REMOVE_LOCAL_FILES_BASED_ON` is set to time or instant
69+
* `-e FREEUP_ATLEAST_GB` - Remove atleast this value in GB on removal (default **80**) - this is ignored if `REMOVE_LOCAL_FILES_BASED_ON` is set to time or instant
70+
* `-e REMOVE_LOCAL_FILES_AFTER_DAYS` Remove local files older than this value in days (default **10**) - this is ignored if `REMOVE_LOCAL_FILES_BASED_ON` is set to space or instant
7171
* `-e READ_ONLY` If Rclone and Plexdrive should be read only or not. 0 means writeable and 1 means read only (default **1**)
7272
* `-e PGID` Group id
7373
* `-e PUID` User id
@@ -174,7 +174,7 @@ Everytime new media is retrieved it should be added to `/local-media`. By adding
174174

175175
By having a cronjob to rmlocal it will sooner or later move media from `/local-decrypt` depending on the `REMOVE_LOCAL_FILES_BASED_ON` setting. Media is only removed from `/local-decrypt` and still appears in `/local-media` because it is still be accessable from the cloud.
176176

177-
If `REMOVE_LOCAL_FILES_BASED_ON` is set to **space** it will only remove content (if local media size has exceeded `REMOVE_LOCAL_FILES_WHEN_SPACE_EXCEEDS_GB`) starting from the oldest accessed file and will only free up atleast `FREEUP_ATLEAST_GB`. If **time** is set it will only remove files older than `REMOVE_LOCAL_FILES_AFTER_DAYS`.
177+
If `REMOVE_LOCAL_FILES_BASED_ON` is set to **space** it will only remove content (if local media size has exceeded `REMOVE_LOCAL_FILES_WHEN_SPACE_EXCEEDS_GB`) starting from the oldest accessed file and will only free up atleast `FREEUP_ATLEAST_GB`. If **time** is set it will only remove files older than `REMOVE_LOCAL_FILES_AFTER_DAYS`. If **instant** is set it will remove all files when running.
178178

179179
*Media is never deleted locally before being uploaded successful to the cloud.*
180180

root/etc/services.d/mongodb/run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ umask 022
55

66
mongodb_command="mongod --logpath ${log_dir}/mongod.log"
77

8-
echo "Executing ${mongodb_command}"
8+
echo "Started ${mongodb_command}"
99
exec s6-setuidgid abc $mongodb_command

root/etc/services.d/mount/run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ umask 022
55

66
mount_command="mount"
77

8-
echo "Executing ${mount_command}"
8+
echo "Started ${mount_command}"
99
exec $mount_command

scripts/rmlocal.script

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,40 @@ rm_time () {
4141
find "${local_decrypt_dir}" -mindepth 1 -type d -empty -delete
4242
}
4343

44+
rm_instant () {
45+
# Generate filelist and iterate through it...
46+
find "${local_decrypt_dir}" -type f |
47+
while read -r n; do
48+
49+
# Find the pathname relative to the root of your remote and store filename
50+
filename="$(echo "$n" | sed -e s@"${local_decrypt_dir}"@@)"
51+
destpath="$(dirname "$n" | sed -e s@"${local_decrypt_dir}"@@)"
52+
53+
# Skip hidden or partial files.
54+
case "$n" in
55+
(*.partial~) continue ;;
56+
(*_HIDDEN~) continue ;;
57+
(*.QTFS) continue ;;
58+
(*.unionfs-fuse*) continue ;;
59+
(*.DS_STORE) continue ;;
60+
esac
61+
62+
# If file is opened by another process, wait until it isn't.
63+
while [ "$(lsof "$n" >/dev/null 2>&1)" ] || \
64+
[ "$(lsof "${local_decrypt_dir}/${n}" >/dev/null 2>&1)" ] || \
65+
[ "$(lsof "${local_media_dir}/${n}" >/dev/null 2>&1)" ]; do
66+
echo "[ $(date $(printenv DATE_FORMAT)) ] File -> ${n} in use. Retrying in 10 seconds."
67+
sleep 10
68+
done
69+
70+
# Move file to remote destination[s], retaining path
71+
echo "[ $(date $(printenv DATE_FORMAT)) ] Moving file -> ${n} to Google Drive."
72+
rclone move $rclone_options "$@" "$n" "$(printenv RCLONE_CLOUD_ENDPOINT)${destpath}" >/dev/null 2>&1
73+
done
74+
75+
find "${local_decrypt_dir}" -mindepth 1 -type d -empty -delete
76+
}
77+
4478
rm_space () {
4579
maxSize=$(($REMOVE_LOCAL_FILES_WHEN_SPACE_EXCEEDS_GB * 1000 * 1000 * 1000))
4680
currentSize="$(du -sb "$local_decrypt_dir" | awk '{print $1}')"
@@ -103,10 +137,14 @@ fi
103137

104138
check_rclone_cloud
105139

140+
echo "Removing files based on ${REMOVE_LOCAL_FILES_BASED_ON}"
141+
106142
if [ "$REMOVE_LOCAL_FILES_BASED_ON" = "space" ]; then
107143
rm_space
108144
elif [ "$REMOVE_LOCAL_FILES_BASED_ON" = "time" ]; then
109145
rm_time
146+
elif [ "$REMOVE_LOCAL_FILES_BASED_ON" = "instant" ]; then
147+
rm_instant
110148
else
111149
echo "[ $(date $(printenv DATE_FORMAT)) ] no option to remove old files"
112150
exit 02

0 commit comments

Comments
 (0)