1

I have a directory of files that need to be copied every night as a backup.

I am using 'smbclient' to backup the files to a Linux machine but I am seeing an issue where if a file is locked the entire copy process will abort with a NT_STATUS_SHARING_VIOLATION error.

Is there any way to get smbclient to keep copying the rest of the files in the directory and gracefully skip over the locked files?

Flyk
  • 1,539
  • 1
  • 21
  • 28
Atari911
  • 768
  • 4
  • 11

1 Answers1

1

Don't use smbclient. Mount the shared drive somewhere using mount.cifs and use rsync to make the backup. Example:

# mount.cifs //server/share /mnt/cifs
# rsync -a /mnt/cifs/directory ~/backups

This would mount the share to /mnt/cifs and then recursively copy directory to ~/backups/directory.

Read up on the usage of rsync since it is a powerful program and has a few gotchas.

hololeap
  • 1,321
  • 1
  • 9
  • 14
  • I could be wrong but if the windows server has a lock on the file then wont the rsync behavior be the same as the smbclient? – Atari911 Mar 06 '15 at 03:05
  • From a [semi-official source](https://lists.samba.org/archive/rsync/2013-January/028037.html): "Rsync does continue after it encounters a permission denied error." This should pertain to your case as well. As far as I have seen, `rsync` never quits on a read error for individual files. – hololeap Mar 08 '15 at 09:10
  • 1
    What do you know, this worked like a charm. Sometimes its just about using the right tool for the job I guess. - The only thing i did different was use cygwin to get an rsync/ssh connection to the windows machine. – Atari911 Mar 09 '15 at 23:28