Move files between two windows file shares on the same server

8,581

Solution 1

When you say, “another shared folder”, do you mean “a folder in a different file share (i.e., a different mapped drive)”?  If so, that’s the issue, and there is no easy, magic fix.  When you move a file from one folder to another on the same volume, all that needs to happen is for the operating system to write a new directory entry in the destination folder and erase the old directory entry in the source folder — the file data doesn’t need to be accessed.  When you copy a file, the OS must read each data block and write it in a new location.  And a move between volumes might as well be a move between physically separate disks — it must be treated as a copy followed by a delete of the source file — because directory entries cannot point to data blocks on a different volume.

P.S. Ironically, a move between physically separate disks might even be faster than a move between partitions (volumes or “shares”) on the same disk, because in the latter case the disk I/O heads need to jump back and forth between the source cylinder(s) and the destination cylinder(s).

Solution 2

Even though I'm late for the feast, still, here is the recipe, and I believe it's a practical method, with some preconditions.

  • The core idea is telling the server to move the objects in a particular location (which of course is in one Samba share) to another location (which of course is in another Samba share).

  • inotifywait is the chef, with the cookers called while, read, and mv. That's the team for our dinner.

  • And the kitchen (or maybe dinning room) looks like this:

Samba shares ├─share.1 │ ├─recv │ ├─to.share.2 │ ├─to.share.3 │ └─[...] ├─share.2 │ ├─recv │ ├─to.share.1 │ ├─to.share.3 │ └─[...] ├─share.3 │ ├─recv │ ├─to.share.1 │ ├─to.share.2 │ └─[...] └─[...]

A user login to, let's say, share.x. If the user wants to move/copy something inside share.x to share.y, here is the operation:

  1. Pick the objects inside share.x, move/copy them to share.x/to.share.y.

  2. The server is monitoring those to.share.* folders with inotifywait, thus it knows it's time to work.

  3. The server moves the objects inside share.x/to.share.y to share.y/recv.

  4. Done!

The preconditions include, a particular folder structure as above, a job/service/script run on the server to do the real mv operation.

I do have my own script code to share with you, but there're a lot of improvements to make:

inotifywait -m "$source_dir" --format '%w%f' -e moved_to,create,modify | while read file; do mv -v "$file" "$dest_dir"; done

Modify those $source_dir and $dest_dir to fit your own need.

I use supervisor to manage a bunch of scripts such as above to make my "Samba teleportation". If you're not familiar with supervisor, please refer to http://supervisord.org/ and other answers about it.

Solution 3

Easiest/quick and dirty way would be to either do it from the server itself, or create a share that has both target shares as subfolders (e.g. \\servername\c$).

Share:
8,581

Related videos on Youtube

olofom
Author by

olofom

Updated on September 18, 2022

Comments

  • olofom
    olofom over 1 year

    Using Windows 7 I have a server with shared folders set up. If I open one of them and take a file and move it to a subfolder it's instant - the file is obviously only being moved on the server. The same for two windows having the same shared folder open.

    If I on the other hand open another shared folder on the same server and move a file between them it takes very long time - like it's downloading the file from the first share to my computer in a temp folder and then uploading it to the other share.

    Is there some way to move files between different shares like this without my computer downloading them in between? I want some speed because it's often quite large files.

    • Steve Reeder
      Steve Reeder over 11 years
      is this all happening on the same machine, or on two different computers running windows 7? It sounds like this is happening on the same machine, but if so - why would you be connecting to file shares located on the machine you are logged into when you could access the files locally?
    • olofom
      olofom over 11 years
      Yes, one computer, one server two (or more) shared folders.
    • beldaz
      beldaz almost 4 years
      What you're wanting to do here is a server-side copy. See wiki.samba.org/index.php/Server-Side_Copy
  • olofom
    olofom over 11 years
    I've been thinking of creating a big share with subfolders instead but that messes up the user access etc. I'd rather find some solution that can be applied to what I already have. Doing it from the server is unfortunately not an option.
  • daniel
    daniel over 11 years
    Is the server itself Windows 7? Or something else?
  • daniel
    daniel over 11 years
    Creating a share above both other shares shouldn't hurt user permissions, especially if you have full access to both shares. If, however, you're talking about a NAS box such as my LinkSys with very limited functionality, that might be a different story.
  • olofom
    olofom over 11 years
    Yes, unfortunately it's some kind of Synology NAS solution where users get access to a shared folder and not subfolders in the tree...
  • DavidPostill
    DavidPostill over 7 years
    Please read the question again carefully. Your answer does not answer the original question. "Even though I'm late for the feast" You are not only late for the feast you are in the wrong restaurant. You are proposing a bash solution when the OP is using Windows 7.
  • mo-han
    mo-han over 7 years
    As you said, please read the question again carefully, @DavidPostill. "Move files between two windows file shares on the same server", the title says. We know it's about CIFS, and about how to move objects between different shares on the same server. clients are running Windows OS, however the server side is not mentioned. I have provided a workaround on Linux, which could meet our questioner's requirement pretty well if the server is running a *nix system with Samba. Even if it's some other OS like Windows Server, my answer still provides a good method, and could be modified to suit it.