How to automatically export Confluence spaces using the CLI

How to automatically export Confluence spaces using the CLI

Problem Description

Exporting Confluence spaces regularly is a common requirement for backup, compliance, or migration purposes. The Confluence Command Line Interface (CLI) provides powerful options to automate this process, including exporting all spaces (or a selected list) on a scheduled basis.

This article explains how to set up automatic exports of Confluence spaces using the CLI, including exporting all spaces, specifying export types, and scheduling the process.

Prerequisites

  • Confluence Command Line Interface (CLI) installed and configured.

  • Appropriate permissions to export spaces in your Confluence instance.

  • Access to the server or environment where you will run the CLI commands.

  • (Optional) Access to Windows Task Scheduler or a cron job system for automation.

Exporting all spaces automatically

1. Export all spaces (standard)

To export all spaces in your Confluence instance, use the following command:

acli confluence --action runFromSpaceList --common "--action exportSpace"

2. Export all spaces as PDF (with custom file naming)

To export all spaces (including personal spaces) as PDF files, with each space exported to its own file named after the space key:

acli confluence --action runFromSpaceList --personal --common "--action exportSpace --space @space@ --exportType pdf --file @space@.pdf"
  • --personal includes personal spaces. Remove this option if you only want global spaces.

  • @space@ is replaced by each space key, so each PDF will be named accordingly (e.g., SPACEKEY.pdf).

3. Export spaces listed in a CSV file

If you want to export only specific spaces, create a CSV file (e.g., Spacelist.csv) with the following format:

space,file 2ETO,ETOxml.zip 3TSa,TSaxml.zip 4CD,CDxml.zip

You can also specify full file paths:

space,file ETO,c:\\Users\ atalie\\ACLI\\zips\\ETO.zip CD,c:\\Users\ atalie\\ACLI\\zips\\CD.zip

Then run:

acli confluence --action runFromCsv --common "--action exportSpace" --file "Spacelist.csv"

Scheduling the export (automation)

To automate the export process (e.g., monthly), schedule the CLI command using your operating system's scheduler:

On Windows

Use Task Scheduler to run the CLI command at your desired interval.

On Linux/Unix

Use cron to schedule the command. Example crontab entry for monthly export:

0 2 1 * * /path/to/acli confluence --action runFromSpaceList --common "--action exportSpace"

Additional notes

  • You can specify the export type (--exportType pdf, --exportType xml, etc.) as needed.

  • File naming can be customized using variables like @space@.

  • For more advanced scenarios, refer to the official CLI documentation.

Troubleshooting

  • Ensure the CLI user has sufficient permissions for all spaces.

  • If exporting fails for some spaces, check the CLI logs for error messages.

  • For questions about CSV formatting or automation scripts, refer to the examples above or contact support.