Operating System - HP-UX
1753463 Members
4688 Online
108794 Solutions
New Discussion

Rsync deletes what it just copied

 
SOLVED
Go to solution
Timothy P. Jackson
Valued Contributor

Rsync deletes what it just copied

Hello Everyone,

 

I am using rsync to copy files from one system to another. I am NFS mounting the file system on the remote system and then doing an rsync from the host directory to the NFS mounted remote directory.

 

rsync -avcu --delete --stats /usr/ud61 /roi2/usr/ud61

 

The process is very very slow and after it copies everything to the NFS mount it then proceeds to delete everything it just copied.

 

What am I doing wrong?

 

Also, what opinions are there about using rsync to a NFS mounted file system. Maybe this is why the rsync is so slow? Maybe there is a better way to do this?

 

Any help, thoughts or opinions would be greatly appreciated!

 

Thanks

Tim

5 REPLIES 5
Dennis Handly
Acclaimed Contributor

Re: rsync deletes what it just copied

>doing an rsync from the host directory to the NFS mounted remote directory.

>rsync -avcu --delete --stats /usr/ud61 /roi2/usr/ud61

 

You're pushing it from the local /usr/ud61 to the remote /roi2/usr/ud61?

And deleting all files in /roi2/usr/ud61 that aren't on /usr/ud61.

 

>Maybe this is why the rsync is so slow?

 

I'm not sure what would be faster than NFS?

Timothy P. Jackson
Valued Contributor

Re: rsync deletes what it just copied

Hi Dennis,

 

Thanks for responding!

 

Yes I am pushing.. But sorry i didn't give you enough detail....

 

when I start the process /usr/ud61 is about 1Gig and has probably 2500 files in it. /roi2/usr/ud61 <the nfs mount> is completely empty.

 

I watch the process and it copies all the data over from /usr/ud61 to /roi2/usr/ud61. When it is done with the copy, it proceeds to delete everything in /roi2/usr/ud61 that it just put there.

 

/usr/ud61 is still the same.

Patrick Wallek
Honored Contributor

Re: rsync deletes what it just copied

>>when I start the process /usr/ud61 is about 1Gig and has probably 2500 files in it. /roi2/usr/ud61 <the nfs mount> is completely empty.

 

If the NFS mount point is empty when you start the rsync process, then you don't need to use the --delete option at all.  

 

Files that get deleted on the receiving side are "extraneous files,"  which means that any files on the receiving side that do NOT exist on the sending side are deleted.  

 

There are several delete type options available in rsync, but they all involve when to delete files on the destination/receiving directory.

 

 

--delete --- delete extraneous files from dest dirs
--delete-before --- receiver deletes before xfer, not during
--delete-during --- receiver deletes during the transfer
--delete-delay --- find deletions during, delete after

--delete-after --- receiver deletes after transfer, not during

 

 

Have a look at the rsync man page for more of an explanation of the rsync delete options.

 

 

Matti_Kurkela
Honored Contributor

Re: Rsync deletes what it just copied

The -a option of rsync tries to preserve many things:

  • symbolic links
  • permissions
  • modification times
  • file owners and groups
  • device files and other special files

If you don't have root access to the NFS-mounted remote directory, all the files in the remote directory will remain owned by you, unless the NFS server OS allows file giveaways (which is a dangerous feature).

 

Being root on the NFS client host does not necessarily mean you have root-level access on the NFS-mounted filesystem: by default, many NFS servers will map the root user at the NFS client to user "nobody" or "nfsnobody" on the NFS server. (This is to prevent someone hacking the NFS client from getting root access to the NFS server too.) To allow root access, you must add some extra options when exporting/sharing the filesystem at the NFS server.

 

Because of any of the above, the rsync command may be unable to preserve the ownerships/permissions as they are at the source. Unless you use the '-P' or '--partial' option, the non-perfectly transferred files (e.g. files with the correct data but incorrect ownership/permissions) will be deleted at the end of the rsync operation.

MK
Timothy P. Jackson
Valued Contributor
Solution

Re: Rsync deletes what it just copied

Thanks everyone for responding!

 

The -P option helped but was not the real issue...

 

I had a problem in my script where it was starting two rsync's back to back. The second one had an invalid path on it, so naturally it did not find anything in the host directory that was the same as the remote directory and deleted everything in the remote directory like it was suppose to.

 

Thanks again for all your inputs!

 

Tim