Programmatically Export Space to HTML

Hello there,

Currently, under Space Tools -> Content Tools -> Export -> Export HTML, i export all the Space and import then into another tool.

But i need to to it manually.

 Is there a way i can programmatically execute this task?

Thanks,

Vitor

3 answers

1 accepted

2 votes
Stephen Deutsch Community Champion Sep 10, 2014

Hi Vitor,

Since you are on OnDemand, I would recommend you use the xmlrpc api, which is very easy to use with python.  You can use the exportSpace method (https://developer.atlassian.com/display/CONFDEV/Remote+Confluence+Methods#RemoteConfluenceMethods-Spaces) to export multiple spaces.  Here is an example of a python script that should save all personal spaces (although I changed it real quick and didn't have a chance to test it out), so you should be able to use it for reference:

#!/usr/bin/python
import xmlrpclib
import time
import urllib
confluencesite = "http://localhost:8090"
server = xmlrpclib.ServerProxy(confluencesite + '/rpc/xmlrpc')
username = 'admin'
password = 'secret'
token = server.confluence2.login(username, password)
loginString = "?os_username=" + username + "&os_password=" + password
filelist = ""
start = True
spacesummary = server.confluence2.getSpaces(token)
for space in spacesummary:
    #if space['name'] == "Problem Space":
    #    start = True
    #    continue
    if start:
        if space['type'] == 'personal':
            print "Exporting user " + space['name']
            spaceDownloadUrl = server.confluence2.exportSpace(token, space['key'], "TYPE_XML")
            filename = spaceDownloadUrl.split('/')[-1].split('#')[0].split('?')[0]
            time.sleep(0.5)
            urllib.urlretrieve (spaceDownloadUrl + loginString, filename)
            print filename + " saved."
            f = open("exportedspaces.txt", 'a')
            f.write(filename + "\n")
            f.close()

If you run into a space that has a problem with export, just change start to false, uncomment the three lines, and put the name of the space in place of "Problem Space".  If you want to export all global spaces instead, change the space['type'] to 'global'.  Hope that's helpful!

1 vote
Davin Studer Community Champion Sep 10, 2014

The Confluence Command Line Interface can do what you are looking for.

https://bobswift.atlassian.net/wiki/display/CSOAP/Documentation#Documentation-exportSpace

Or try the Plugin Scroll HTML Exporter.

  • The export ist better.
  • You can customize it.
  • You can use a REST API to initiate and retrive a fresh generated export.

We like it very much and export whole spaces on a regular basis for an offline emergeny handbook.

- Steffen

 

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

387 views 21 10
Join discussion

Atlassian User Groups

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!

Find my local user group

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

Groups near you