-2

I have a regular task that I need to swap out a live/accessed dir with a new version of it.

  • There is a live dir with resources in it: dir/
  • Goal is to swap this out with dir_new/ and cause as little disruption in access to the dir.
  • The content is live/accessed. Stopping access to the directory from end users is out of scope. I would just do this during a downtime window otherwise.

Here's how I do it now:

mv dir dir_old && mv dir_new dir

This works fine, but I'm not sure if any experts have a faster/more reliable way?

  • The filesystem is xfs
  • The "new" dir cannot have ANY content from the existing dir in it, so moving in place, dealing with files didn't seem like it would work.
  • Perhaps rsync with a --delete option? However a requirement is to change "everything" at once in the dir. In other words I can't have a mix of files from the new and old mixed together.
  • 1
    This question contains a ton of mixups and is not clear. Rsync and other file sync mechnaisms are not swapping folders (as the quesxdtion indicates). Comments on an answer say it is a life folder which can nto b e taken down, which is missing information. The OP does not spend time thinking this through and expects people answering to do all the work. – TomTom Oct 16 at 16:40
  • 1
    This is absolutely an X/Y problem. I seriously doubt you will get the answer you want from this question, because your approach is very wrong. You need to clearly define what it is you would like to accomplish and why, without considering the technical semantics of managing a filesystem - because there is a lot of confusion there in this question, and I don't think you'll get there by asking about this approach. – Spooler Oct 16 at 16:54
0

The absolute fastest way, per definition, is not to move them at all - which basically means stopping all access to them and then - doing a swap by RENAMING the directories. Renaming is a metadata only operation, no data is being copied, and such it is a lot faster than anything else.

"he "new" dir cannot have ANY content from the existing dir in it,"

This makes no sense. Then swap it out with an empty folder, which you can prepare first. Not sure what this even means in the context of "swapping directories".

| improve this answer | |
  • This is a live/accessed dir, so stopping all access to them is out of scope. I would just do this during downtime if that was the case. Your second comment about it not making sense: I can't swap it out with an empty folder, I need the content from the new dir. The new dir isn't empty it's full of new content. – Rino Bino Oct 16 at 16:36
  • This is not mentioned in your question, as is not mentioned what you do there. Also you talk about SWQAPPPING, which is NEVER possible with life access - even a mv is technically NOT SWAPPING. And I still do not understand what you mean with it is full - if you swap them then you have original content. Unclear. Voting to close quesiton. – TomTom Oct 16 at 16:39
  • I've edited my original post to hopefully clear up some of your confusion. Also, isn't mv dir dir_old a "rename" ? I've never heard of "rename" in linux so please help me out, I've always just used mv to rename things. – Rino Bino Oct 16 at 16:41
  • Sorry, do not care. After insulting me here - someone else may answer or not. – TomTom Oct 16 at 16:50
0

Neither of the directories should be named dir. Rather, dir should be a symbolic link to the directory containing the files you want to be used. You can then change the link atomically whenever necessary.

For example, name your directories e.g. dir_20200917, dir_20201015, etc. Then link to the one which should be live:

ln -sf dir_20201015 dir

Note that -f here will replace the existing symlink, if any.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.