Is there a way to batch search and replace within Confluence?
I have found an abandoned plugin which does this, but it does not support Confluence 3.4+
Is there a way to do this through webDav maybe? My attempts have failed at the point of accessing the Network Place for Confluence through various batch editors - all of which don't seem to be able to pickup the files in Confluence.
Any ideas / solutions would be appreciated.
Thanks - Mick
I've not used CLI before and I'm sure that will service all your needs, however more of an FYI. This weekend i sucessfully used Jeans's resolve in a similiar question i posted. See: https://answers.atlassian.com/questions/12526/confluence-wiki-markup-search-and-replace. this uses a plugin and regex queries. I sucessfully ran this against a confluence 3.5.11 instance to change wide range of user macros before upgrading to 4.0.
Thanks for the suggestion.
I looked at that plugin as a starting point but then steered clear simply because it was a bit hacky. With confirmation from you that you have successfully used it and everything is going well, I think I will give this a go on a trial basis to see if it will successfully work for me also.
Do you have any tips / tricks of things to try and avoid or suggested operations to make it easy to use?
I will be installing today, so hopefully I have it all worked out by this time tomorrow.
Thanks again. Mick
yeah I know what you mean about being a bit of a hack - i had exactly the same concerns. below is my my advice /experience when used against confluence 3.5.11 running on Ubuntu 10.4 LTS.
global-search-replace-plugin-1.2.1.jar into confluence
$ mkdir ~/META-INF $ mkdir ~/META-INF/lib $ mv backport-util-concurrent-3.1.jar ~/META-INF/lib/ $ jar uf global-search-replace-plugin-1.2.1.jar META-INF/lib/backport-util-concurrent-3.1.jar
Well the plugin is installed, but it's not working for us.
We are getting a "page not found" error when we navigate to the /plugins/servlet/searchReplace page.
It's not obvious what is causing the problem, all permissions look good and the plugin shows up as functional. Oh well. Luckily I have Bob's suggestion to fall back on - I'll be testing this today so fingers crossed it all works out.
that's a shame you cannot get this to work. I will use the email address you posted earlier (in Bob's thread) and attach the plugin jar file (with the back port embeded) that I uploaded and used against confluence 3.5.11. I'll do this in the next couple of hours once I'm at work.
You can use Confluence Command Line Interface to script getPageSource and storePage after doing search and replace. If your use case is simple enough, you can use findReplace parameter on the storePage to do the replacement.
Example scripts are https://bitbucket.org/bob_swift/confluence-cli/src/tip/src/main/resources/examples/replace.sql and https://bitbucket.org/bob_swift/confluence-cli/src/tip/src/main/resources/examples/replace.txt
Thanks Bob. I have installed Confluence CLI and have just starting to play around with it.
The documentation is really good btw - great job!
Ideally, I would like to search and replace on all descendents under a specified page. If I wanted to replace the word HELP with Get Support could I do something like this?
confluence --action storePage --space "space name" --title "page name" --descendents --findReplace "Help:Get Support"
I have tried this out and it reports back successfully, but the page itself doesn't update. Does this script look right to you?
I have made some progress and have two command line scripts working.
Add page contents to output file:
confluence --action getPageSource --space "Space Name" --title "Page Name" --file out.txt
Replace page with itself and run findReplace
confluence --action storePage --space "Space Name" --title "Page Name" --file out.txt --findReplace "Help:Get Support"
This is all working nicely. Now I am trying to insert these two command line scripts into a script file which will work through each page outputting its contents, then updating its contents and running --findReplace.
Is this the right direction do you think for a batch change?
Are there any examples of run scripts for Confluence CLI available?
I think you are on the right path. Here is an example I can add. You should be very careful to test this and consider using --simulate support and or limit your query to a test space. One key is to make sure your query only selects pages that have your replacement string so that only those pages get a new version with the updated text.
I can't add this as an attachment, so it might get messed up
# Run using something like
# confluence --action runFromSql --file src/main/resources/examples/replace.sql --database confluence-3.5.0 --host imac.local --driver postgresql
# where replace.txt looks something like:
# --action getPageSource --space @space@ --title "@title@" --file out.txt
# --action storePage --space @space@ --title "@title@" --file out.txt --findReplace "Help:Get Support"
'run' as action,
'src/main/resources/examples/replace.txt' as file,
'@space@:' || s.spacekey || ',@title@:' || c.title as "findReplace"
from content as c, bodycontent as b, spaces as s
c.contentid = b.contentid
and s.spaceid = c.spaceid
and c.content_status = 'current'
and c.contentid = b.contentid
and b.body like '%Help%'
and c.contentid is not null
and c.spaceid is not null
Would you mind emailing me the attachment ... firstname.lastname@example.org
I am not sure I exactly follow yet, I will give it a go on a limited basis and see if I can get it to work.
It is obvious that the CLI is very powerful once you get it working and know how to command it. I am not sure I am there yet :(
Thanks for all the advice.
I got the scripts to work, but hit a snag. I am trying to replace a fairly complicated macro which includes multiple variables etc. The text includes such characters as , % : and in turn this confuses the scripting.
Likewise the replacement text also includes complicated text which includes , $ :
From the experiments I did, there isn't a way to replace text that includes these special characters due to the way the scripting works. Is that right Bob?
Is there a way to specify "This is the: exact text; that I want $$ to replace%?"
This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.Read more
To anyone who doubts that Atlassians are a little too obsessed with collaboration, and tools related thereto, let me describe a recent discussion we had (which took place on our internal Confluence, ...
Connect with like-minded Atlassian users at free events near you!Find a group
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no AUG chapters near you at the moment.Start an AUG
You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs