开发者

svn moving directories to reorganize repo

I have a svn repo containing main directories like this:

/apples/
/bananas/
/pears/

In my working copy, those are actually subdirectories of a much bigger tree...

/food/fruit/apples
/food/fruit/bananas
/food/fruit/pears
/food/veggies/asparagus
/food/veggies/broccoli

I would like to reorganize my repo so that /food/ is in fact the root of the repo... but my working copy is a live server, so I need to be very careful not to break anything, even for a minute. It's also a really large tree, so rolling back a mistake could potentially create a noticeable downtime.

If this were just moving folders within the repo, I think I'd know how to use svn move with repo arguments (and I assume that is still step #1?)... but I'm not sure how to apply the change to the working copy, then add the parent folders, while not screwing up the existing working files.

MY ANSWER:开发者_运维技巧 thanks to A.H.

1) Make sure the repo is up-to-date and then move the branch within the repo. This can be done using svn move commands on the repo itself or through actions on a working copy. This does not affect the live working copy (don't svn update yet!). This is the easy part.

2) svn switch the branch to the new location. In this example, whereas fruit was previously the root of the repo:

svn switch https://host/svn/fruit /food/fruit

I didn't know much about svn switch previously, but this wasn't too tricky. This changes all the .svn metadata, but does not affect actual files.

3) Here's the tricky part. You need to take these steps in rapid succession for minimal downtime (they're each very fast):

mv /food/fruit /food/fruit-temp
svn co --depth immediates https://host/svn/ /food/
rm -rf /food/fruit
mv /food/fruit-temp /food/fruit
svn update --set-depth infinity /food/

What's happening here is that the checkout with --depth immediates creates the metadata for the contents of /food/ and creates the /fruit/ subdir but not its contents (we need to use rm -rf so we can get rid of the .svn folder inside fruit, but that's all that's there). Then we just swap the real content back in, and the parent and child are now stitched together. Once the mv is done, we're back online. The set-depth infinity extends the scope of the working copy to what you'd expect. Finally we can svn add the child's siblings (eg- veggies).


My first tip is to do start with a fresh working copy which is NOT live. In that working copy (WC) you can try out things without any danger. Thats what working and copy really means ;-)

Another tip: Use the second working copy to rearrange the existing structure step by step into the structure you want. After everything is in place, check in. Please keep in mind that rearrangements must be done using the svn commands.

Then use another working copy to check, that your last checkin did indeed what you indented.

Then you can update your live working copy OR simple switch that last WC with the live site using the normal mv command.

Step by step:

svn co $URL new-wc
cd new-wc
svn mkdir food
svn mkdir food/fruit
svn mv apples food/fruit
svn mv bananas food/fruit
svn mv pears food/fruit
svn ci

Now checkout a fresh WC to verifiy - the live WC is still unchanged!

cd ..
svn co $URL verify-wc
# take time and verify

Now switch the live WC and the verify WC in the filesystem - this is fast if they are on the same filesystem!

mv live-wc live-wc-old
mv verify-wc/food/fruit live-wc

Now the live WC is fixed. An alternative for the ast block can be:

cd live-wc
svn switch $URL/food/fruit

This should do nothing time consuming - but please check this with a backup copy first :-)


I would build a replacement and then use svn switch on your live working copy to switch to it.

1) svn copy your entire working directory to a new working directory

2) Create the parent folders in your new working copy

3) svn copy or move files from their current relative location in the copy to the intended locations.

4) When you are perfectly happy with the setup of the new working copy, commit it

5) Now, in your live version, use svn switch to retarget to the new working directory

Momentarily your server will suffer some reorganization as SVN removes the existing files and checkouts the new files. But it will be as fast as the svn switch command can make it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜