LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Need help with RSYNC (https://www.linuxquestions.org/questions/linux-software-2/need-help-with-rsync-572309/)

ryanlum 07-25-2007 10:40 PM

Need help with RSYNC
 
hey guyz,

I am currently using rsync.. i have a problem though.. if i were to copy the files from the folder, and currently rsync is using the file, the mv will fail.

Is there anyway to go around this to let the script know that the file is currently being used by rsync?

chrism01 07-26-2007 01:48 AM

If rsync is reading the file and you want to cp the file, that will work.
If rsync is reading the file and you want to mv the file, check cmds lsof, fuser.
Ditto the latter if rsync is writing to the file.

gloriant 07-26-2007 02:01 AM

you're mingling two concepts here, copy files and the command mv which will move and/or rename files (from one location to another).
Making a copy of the file in use should not be a problem.

ryanlum 07-26-2007 03:11 AM

i just want to use mv.

you suggested to use cmds lsof, fuser

how do you use it and which one is better?
becuase i will need to mv the file

ryanlum 07-27-2007 08:27 AM

i tried rsync on the command losf...
but it can't seem to detect the file when its being transfered by rsync.
but it doesn't have any probelms for ftp.
any ideaS?

gloriant 11-27-2009 07:27 AM

Quote:

Originally Posted by ryanlum (Post 2838555)
i tried rsync on the command losf...
but it can't seem to detect the file when its being transfered by rsync.
but it doesn't have any probelms for ftp.
any ideaS?

You could do it like this:

Code:

# file is the file to move.  This should best be absolute path (and even realpath)
file=/home/me/test/file13.txt

# destination is where you want to move the file to. this example suggests it to be
# a directory.
destination=/tmp

# PROC is the name of the process you suspect to be interfering.  This name should be
#  a name that would appear as first field in an lsof output.
PROC=rsync

# PROCUSER is the user the suspected PROC could be running as.  Leave empty if unknown.
# e.g.: PROCUSER=${USER};
PROCUSER="";

[ -z "${file}" ] && echo "ERROR: file is not set." >&2 && exit;
[ ! -f "${file}" ] && echo "WARNING: ${file} is no file";

[ -z "${destination}" ] && echo "ERROR: destination is not set." >&2 && exit;
[ ! -d ${destination} ] && echo "WARNING: ${destination} is no directory";

# we're looking in the lines of lsof, for a match on
#  running process,... by running user,... keeping file open.
SEARCH='^'${PROC}[ \t].*[ \t]'${PROCUSER}'.*[ \t]'${file}'$';

if ! lsof | grep -q -E "${SEARCH}"; then
  mv ${file} ${destination};
fi



All times are GMT -5. The time now is 05:40 PM.