Using RSYNC to mirror/copy Confluence folders

Still need help?

The Atlassian Community is here for you.

Ask the community


Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.

Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles for non-Data Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

The steps outlined on this article are provided AS-IS. This means we've had reports of them working for some customers — under certain circumstances — yet are not officially supported, nor can we guarantee they'll work for your specific scenario.

You may follow through and validate them on your own non-prod environments prior to production or fall back to supported alternatives if they don't work out.

We also invite you to reach out to our Community for matters that fall beyond Atlassian's scope of support!

Confluence folders could grow significantly over time. Consequently, deploying a new node or relocating your shared folder can become a time-consuming process, sometimes not fitting in your available maintenance window.

To streamline the transition of home and shared folders, consider setting up a mirrored folder. This approach ensures that you have a reliable copy of the original folders readily available when needed.

For this, we will use the RSYNC tool to replicate or copy Confluence folders from one place to another to keep them in sync.

(warning) It's important to note that this mirror folder is intended to facilitate faster transitions and should not be considered a replacement for a comprehensive backup solution.

Solution

Let's say we have two folders, and we want Folder_B to an exact copy of Folder_A.

  • Origin folder called Folder_A
  • Destination folder called Folder_B

(info) These could be in the same server or not by using mounting points or scp like paths (username@remote_server:/folder/path).

  • First let's create a command that will check what is in Folder_A and is not in Folder_B. This way every time it runs it will copy/delete only what changed.
rsync -av --delete --log-file=/path/to/rsync_log.txt /path/to/folder_a/ /path/to/folder_b/
      • -a: This is the archive mode, which preserves permissions, timestamps, symbolic links, and other file attributes.
      • -v: This option enables verbose output, which will provide detailed information about the syncing process.
      • --delete: This option ensures that files in folder_b that are not present in folder_a are deleted, keeping the destination folder an exact mirror of the origin.
      • --log-file=/var/log/rsync_log.txt: This option specifies that the output of the rsync command should be written to a log file named rsync_log.txt in folder /var/log/.
    • (warning) Depending on the system permissions you might need to add the sudo command before the line.
    • (info) Please change the folder path to match your needs.
  • (optional) We can keep the folders in sync automatically by using cron. You can edit your crontab by running crontab -e in the terminal and add the following line: In this example we will sync the folders every hour. 
0 * * * * rsync -av --delete --log-file=/path/to/rsync_log.txt /path/to/folder_a/ /path/to/folder_b/
  • After adding this line, save and close the crontab file. The rsync command will then be executed every hour, and its output will be logged to the specified log file.
  • Before executing the planned change, it is recommended to stop Confluence and run the command one last time for a complete trustworthy copy. 
  • Lastly you can do some check to see if they folders are matching.
How to compare if the destination folder as the size and the same amount of files has the origin by running the following commands on folder_a and folder_b
find /path/to/folder_a/ -type f | wc -l
du -sh /path/to/folder_b/
  • (warning) If Confluence is running, you will probably see smalls differences as the application is always reading and writing files.

Related pages

Confluence Data Center disaster recovery

Backup and Restore

Production Backup Strategy





Last modified on Aug 20, 2024

Was this helpful?

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