Subscribe

Copying a file from the .snapshot directory fails

Hello.

A user reported the following problem that I have also reproduced:

Working in a Linux workstation accessing one NetApp volume through NFS, when trying to copy a file from one snapshot (.snapshot/dir1/filename) to the targetlocation where the original file exists, p.e. when you have done some changes over the file and you want to restore the backup copy from the .snapshot dir, it will fail telling that both are the same file.

  It says: "cp: 'filername' and '/path/to/filename' are the same file"

It's obvious that both files are different and there is a workaround that avoids the error, just renaming or deleting the file in the target directory before copying the file over.

What I don't understand is why the system is telling that both files are the same?

Regares

Copying a file from the .snapshot directory fails

One of the checks the cp command does before copying a file is an inode check.  Files in the snapshots have the same inode as the files on the live filesystem - cp sees this and thinks they are the same file.  From what I have read, NetApp is at fault for not being POSIX compliant in that it allows the same inode # to be used for different files, though I suppose you could make the argument that the older snapshot is not technically a different file.

I saw someone recommend using the --backup option to copy.  I've also written one-liner tar commands to replace a directory or set of files - tar cvf - <snapdir> | tar xf - -C <nonsnapdir>, or tar cvvf - <snapdir> | (cd <nonsnapdir> ; tar xf -).