Last active
April 3, 2018 13:25
-
-
Save mfaux/481d53c80408334cbdc825f0f510b977 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[string]$old, | |
[string]$new | |
) | |
$domain = "configit.atlassian.net" | |
$infile = ".\entities.xml" | |
$outfile = ".\new-entities.xml" | |
$oldLower = $old.ToLower() | |
$newLower = $new.ToLower() | |
$batch = 1000 | |
Get-Content $infile -ReadCount $batch | | |
ForEach { | |
$_ = $_.Replace( "[CDATA[$($old)]", "[CDATA[$($new)]" ) | |
$_ = $_.Replace( "[CDATA[$($oldLower)]", "[CDATA[$($newLower)]" ) | |
$_ = $_.Replace( "spaceKey=$($old)", "spaceKey=$($new)" ) | |
$_ = $_.Replace( "[$($old):", "spaceKey=[$($new):" ) | |
$_ = $_.Replace( "key=$($old)]", "key=$($new)]" ) | |
$_ = $_.Replace( "<spaceKey>$($old)</spaceKey>", "<spaceKey>$($new)</spaceKey>" ) | |
$_ = $_.Replace( "ri:space-key=`"$($old)`"", "ri:space-key=`"$($new)`"" ) | |
$_ = $_.Replace( "ri:space-key=$($old)", "ri:space-key=$($new)" ) | |
$_ = $_.Replace( "<ac:parameter ac:name=`"spaces`">$($old)</ac:parameter>", "<ac:parameter ac:name=`"spaces`">$($new)</ac:parameter>" ) | |
$_ = $_.Replace( "<ac:parameter ac:name=`"spaceKey`">$($old)</ac:parameter>", "<ac:parameter ac:name=`"spaceKey`">$($new)</ac:parameter>" ) | |
# web links | |
$_ = $_.Replace( "//$($domain)/wiki/display/$($old)/", "//$($domain)/wiki/display/$($new)/" ) | |
$_ = $_.Replace( "//$($domain)/wiki/display/$($oldLower)/", "//$($domain)/wiki/display/$($newLower)/" ) | |
$_ = $_.Replace( "//$($domain)/wiki/spaces/$($old)/", "//$($domain)/wiki/display/$($new)/" ) | |
$_ = $_.Replace( "//$($domain)/wiki/spaces/$($oldLower)/", "//$($domain)/wiki/display/$($newLower)/" ) | |
Add-Content $outfile $_ | |
} | |
$infile = ".\exportDescriptor.properties" | |
$outfile = ".\new-exportDescriptor.properties" | |
(Get-Content $infile).Replace( "spaceKey=$($old)", "spaceKey=$($new)" ) | Set-Content $outfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
rename-space-keys.ps1
This script is intended to make it easier to copy a space in Confluence Cloud (for example, when versioning product docs).
This script renames the keys in Confluence Cloud space export following the directions in Solution 2: Manually Clone Or Rename A Space, an unsupported solution provided by Atlassian.
This script is suitable for large files, and processes 1000 lines of text in memory at a time.
Usage
In the script, replace the value of
$domain
with your Confluence Cloud domain.In PowerShell, go to the folder of your unzipped XML space export. Run
rename-space.ps1
, passing the old space key in-old
and the new one in-new
. For example:The script outputs two files:
new-entities.xml
new-exportDescriptor.properties
The original files remain untouched.
You will need to remove the 'new-' prefixes when zipping up your content prior to importing the new space into Confluence.
Limitations
This script does not rename space names. After running the script, you can edit
new-entities.xml
, and[CDATA[Old space name]
with[CDATA[New space name]
[CDATA[old space name]
(lower case) with[CDATA[new space name]
Performance