AEM Developers, raise your hand if you’ve never broken a local AEM instance. If you did raise your hand, you just might be the most diligent AEM developer out there! Full disclosure, I break my local AEM instances more times than I can count, and usually, I have to redo my local AEM setup.
My manual AEM setup steps include:
- Redeploy dependencies (ACS commons/connectors/code and content packages)
- Setup replication agents
- Setup integrations (such as dynamic media)
- <insert other manual tasks here>
Every time I break an AEM instance, it’s a major inconvenience and that’s why I wrote AEM Backup CLI. In this post, I will explain how to use it and provide some additional details.
What is AEM Backup CLI
It is a tiny Command Line Interface that packages the AEM crx-quickstart
folder so that we can restore it when needed. Everything you set up on an AEM instance is inevitably stored in the filesystem under the crx-quickstart
folder, which makes it extremely easy to backup the whole instance. The only caveat, you have to do a backup while your AEM instance is stopped. Which is not bad since you’ll be doing this for local development only.
Installing AEM Backup CLI
- If you don’t have it already installed, install Node.js and grab the LTS version
- Next, install the CLI:
npm install -g aem-backup-cli
- You should now be able to run
aemb
and see the artwork (screenshot below) - Type
exit
to exit out of the CLI for now.
Before You Backup
Let’s cover some ground rules:
- You should only run
aemb
once you are in the AEM directory. (the directory that contains the AEM jar and thecrx-quickstart
folder) - You should only run
aemb
after your AEM instance has been completely shutdown. (see: https://github.com/ahmed-musallam/aem-backup-cli#how-it-works)
Your First Backup
Okay, so now that we’ve covered the ground rules, let’s perform a backup!
Let’s say that I have already installed all my packages and configured everything on my local author instance. And then let’s say that my local author instance is located at /Users/admed.musallam/Development/AEM/6.4
. Now, I shutdown my instance and run:
-
cd /Users/admed.musallam/Development/AEM/6.4
-
aemb
Now I can use any of the aemb
commands, you can see those by typing help
Run backup initial-backup-2019.1.24
. I named this backup initial-backup-2019.1.24
, but you can name it whatever you want. You can also create multiple backups (with different names).
So now you have a backup of the whole AEM instance! This process takes ~7 seconds on my 2014 MackbookPro 2.5GHz Core i7 – 16GB RAM..
Restoring Your Backup
Follow the same steps above but stop your AEM instance, cd
into your AEM directory, and run aemb
.
And this time, type restore
. You will be prompted to select a backup from a list of backups. I went ahead and created 2 other backups:
I selected my original backup and replied y
at the prompt:
My backup is now restored and I can start my AEM instance!
Other Commands
The CLI includes two other commands you can use delete
and list
and they are self-explanatory.
Advanced Usage
Read the documentation to understand how the tool works. Since the tool archives the whole crx-quickstart
folder, and adds the archives under crx-quickstart.backups
, you can copy any of the generated archives and paste them in a different AEM instance folder (under crx-quickstart.backups.
You should be able to use the tool in the same way with the new instance.
Possible scenarios:
- You want to copy a certain backup to another AEM instance on your machine
- You want to share an AEM backup archive with your fellow developers to get started quickly (granted you have a way to share a ~3GB file)
Hope you like the tool and use it in your projects. Please star the repo if you thought it was helpful!
Photo by Mr Cup / Fabien Barral on Unsplash
Can we user AEM Backup CLI tool for Linux our version is AEM 6.4 SPS2
It “should” work on linux but I have not tested it. Give that a shot and let me know.
As an FYI, this is tool should not be used in production or in any other environment other than your local development machine. For Dev/Prod and others there are other backup tools and practices.