Last active
October 22, 2024 09:11
-
-
Save kmccarth/7c6bb4fe4b2fdf107c222d7e9cd61fab to your computer and use it in GitHub Desktop.
I needed to export our Confluence instance, here was a super easy way to get all pages, and create a file for each page (named after the article) and the page's resulting HTML.
This file contains hidden or 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
#!/bin/bash | |
export CONFLUENCE_USERNAME="your_username" | |
export CONFLUENCE_PASSWORD="your_password" | |
function get_page_html() | |
{ | |
mkdir ~/confluence; | |
result=$(curl --request GET \ | |
--url "https://ventureapp.atlassian.net/wiki/rest/api/content/$1/?expand=body.export_view" \ | |
--user $CONFLUENCE_USERNAME:$CONFLUENCE_PASSWORD \ | |
--header 'Accept: application/json' \ | |
--header 'Cache-Control: no-cache' \ | |
--header 'Content-Type: application/json'); | |
title=$(echo $result | jq '.title' | sed 's/\"//g' | sed 's/[][*]\|[[:space:]]//g' | sed "s/ /-/g"); | |
file=~/confluence/$title.html | |
touch $file; | |
body=$(echo $result | jq '.body.export_view.value' | sed 's/^.\(.*\).$/\1/'); | |
echo $body > $file; | |
} | |
function listpages() | |
{ | |
limit=500; | |
loops=1; | |
for ((i=0;i<=$loops;i++)); do | |
start=$( expr $i '*' "$limit" ) | |
results=$(curl --request GET \ | |
--url "https://ventureapp.atlassian.net/wiki/rest/api/content/?limit=$limit&start=$start" \ | |
--user $CONFLUENCE_USERNAME:$CONFLUENCE_PASSWORD \ | |
--header 'Accept: application/json' \ | |
--header 'Cache-Control: no-cache' \ | |
--header 'Content-Type: application/json'); | |
ID=$results | jq '.results[] | .id' | sed 's/\"//g' >> ~/repos/hqo/json.txt; | |
get_page_html $ID; | |
done | |
} | |
listpages(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment