How do I create individual space exports of all spaces via the command line interface

Still need help?

The Atlassian Community is here for you.

Ask the community

Purpose

This will allow you automatically create space exports of all spaces with just one command. Modified from here: http://www.antelink.com/blog/how-automatically-export-full-confluence-space.html

Solution

  • Create the following script, and save it as backup.sh (don't forget to modify the first 5 lines to fit your environment!):

    #!/bin/bash
      
    ### /!\ Don't forget to adapt the following 5 lines /!\
    CONFLUENCE_BASH='/Users/test/AtlassianApps/SupportTools/confluence-cli-4.4.0/confluence.sh'
    STORE_DIRECTORY='/Users/test/AtlassianApps/SupportTools/confluence-cli-4.4.0/backup'
    SERVERLOCATION='http://localhost:8574/c574'
    USERNAME='admin'
    PASSWORD='admin'
      
    ########################################################
      
    set -u
    set -e
      
    BACKUP_DIRECTORY="$STORE_DIRECTORY/confluence_space_backup-`date +%Y%m%d`"
    mkdir $BACKUP_DIRECTORY
    if [ $? -ne 0 ]
    then
        echo "CRITICAL - `date` - problem during the creation of the directory $BACKUP_DIRECTORY"
        exit 1
    fi
      
    LIST_SPACES=`$CONFLUENCE_BASH --action getSpaceList --personal --server "$SERVERLOCATION" --password "$PASSWORD" --user "$USERNAME" | tail -n+3 |  awk 'n>=1 { print a[n%1] } { a[n%1]=$0; n=n+1 }'`
    if [ $? -ne 0 ]
    then
        echo "CRITICAL - `date` - problem during retrieving the spaces list"
        exit 1
    fi
    echo "DEBUG - `date` - success to retrieve the spaces list"
      
    printf %s "$LIST_SPACES" | while IFS= read -r line
    do
        SPACE_SHORTNAME=`echo $line | cut -d ',' -f1 | sed -e "s/\"//g" | sed -e "s/ /_/g"`
        SPACE_LONGNAME=`echo $line | cut -d ',' -f2 | sed -e "s/\"//g" | sed -e "s/ /_/g"`
        SPACE_BACKUP_FILE="$BACKUP_DIRECTORY/$SPACE_LONGNAME.zip"
              
        echo "DEBUG - `date` - start to save the space $SPACE_SHORTNAME as $SPACE_BACKUP_FILE"
        $CONFLUENCE_BASH --action exportSpace --space "$SPACE_SHORTNAME" --file "$SPACE_BACKUP_FILE" --server "$SERVERLOCATION" --password "$PASSWORD" --user "$USERNAME" > /dev/null
        if [ $? -ne 0 ]
        then
            echo "CRITICAL - `date` - problem during retrieving the spaces list"
            exit 1
        fi 
               
    done
  • Run the script, by "cd" to the directory containing this script, and run this:

    ./backup.sh

 

Last modified on Feb 26, 2016

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.