Rsync script moving half-formed files

Hey Guys,

First time poster. Go easy on me:)

So I have a simple script that runs every 30 seconds per a time scheduler. This script and scheduler run as expected.

Here is the .timer file and the bash script linked to the timer:

[danielh@turin system]$ cat port_to_plex.timer
Description=Timer for port_to_plex



[danielh@turin scripts]$ cat
#! /bin/bash
rsync -rt --remove-source-files /home/danielh/port/* danielh@
find /home/danielh/port/ -mindepth 1 -maxdepth 1 | xargs rm -rf

[danielh@turin scripts]$

Now, the goal of this script is simple. On a routine basis, move files from a local directory to a remote directory (my plex server which is running rsync and arch/manjaro).

The issue I am having is that if I move a big file to this folder, and if the script runs at the same time the file is still being moved, rsync will move the file anyways… essentially stopping the transfer and then moving a half formed/moved file.

Any ideas or better ways to go about doing this?

Thanks for any suggestions or help ahead of time~

Hi @Nooze, and welcome!

I don’t know if it’ll fix your problem, but you can also look at inotifywait to trigger the script when necessary. That way it causes less overhead to get the job done, because the script runs only when triggered, and only once.

Another option is to use a lock file. When you start the copy process create a temporary file that. When the process has successfully completed, delete the above created file again. In the script, set a check for the file, and only when it’s not present, start the copy process.