Creating and Restoring Backups for Alfresco with Docker Compose

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating and Restoring Backups for Alfresco with Docker Compose

angelborroy
Alfresco Employee
2 8 8,791

This blog post describes required operations in order to create and restore an ACS Backup when using Docker Compose deployments.

Following project has been used in order to generate the Docker Compose templates:

https://github.com/alfresco/alfresco-docker-installer

Creating Initial ACS Deployment

In order to create the initial ACS Deployment, just use the Yeoman generator provided by Alfresco with default options.

$ mkdir alfresco-1
$ cd alfresco-1

$ yo alfresco-docker-installer ? Which ACS version do you want to use? 6.2 ? How may GB RAM are available for Alfresco (8 is minimum required)? 12 ? Do you want to use HTTPs for Web Proxy? No ? What is the name of your server? localhost ? What HTTP port do you want to use (all the services are using the same port)? 80 ? Do you want to use FTP (port 2121)? No ? Do you want to use MariaDB instead of PostgreSQL? No ? Are you using different languages (this is the most common scenario)? Yes ? Do you want to create an internal SMTP server? No ? Do you want to create an internal LDAP server? No ? Select the addons to be installed: ? Are you using a Windows host to run Docker? No ? Do you want to use a start script? No

Add the following lines in the volumes section for the service solr6 in generated docker-compose.yml file.

solr6:
...
    volumes:
        - ./data/solr-data:/opt/alfresco-search-services/data
        - ./backup/solr/alfresco:/opt/alfresco-search-services/backup/alfresco
        - ./backup/solr/archive:/opt/alfresco-search-services/backup/archive

This volumes will be used to store the solr backup.

Start the deployment and verify everything is up & running.

$ docker-compose up --build --force-recreate

Use the Share Web Application to add some new folders and files to the repository. By default this application is available in http://localhost/share

Creating an ACS Backup

Alfresco Backups must be performed following the next order:

  • SOLR Cores
  • Database
  • Filesystem

If you are using SOLR Cores for alfresco and archive, you need to perform a backup for every core using SOLR REST API.

$ curl -u admin:admin "http://localhost/solr/alfresco/replication?command=backup&location=/opt/alfresco-search-services/backup/alfresco/&numberToKeep=1&wt=xml"
$ curl -u admin:admin "http://localhost/solr/archive/replication?command=backup&location=/opt/alfresco-search-services/backup/archive/&numberToKeep=1&wt=xml"

If both commands are sucessfully executed, following folders will be available in your local host.

$ tree -L 3 backup
backup
├── solr
    ├── alfresco
    │   └── snapshot.20210216150258667
    └── archive
        └── snapshot.20210216150306103

Once Solr backup is ready, perform a Postgres Dump (Database) using following command.

$ docker-compose exec postgres pg_dump --username alfresco alfresco > backup/pg-dump.sql

You can use some other approach, like zipping the output of the dump, but we are using the simplest one.

Finally, filesystem needs to be saved. The following command is using rsync program in order to get this done.

$ rsync -r data/alf-repo-data backup

At this point your ACS Backup is complete. You'll find all the elements living in backup folder.

$ tree -L 3 backup
backup
├── alf-repo-data
│   ├── contentstore
│   └── contentstore.deleted
├── pg-dump.sql
└── solr
    ├── alfresco
    │   └── snapshot.20210216150258667
    └── archive
        └── snapshot.20210216150306103

Restoring the Backup in a new deployment

Create a new Docker Compose deployment in order to restore your backup.

$ mkdir alfresco-2
$ cd alfresco-2

$ yo alfresco-docker-installer
? Which ACS version do you want to use? 6.2
? How may GB RAM are available for Alfresco (8 is minimum required)? 12
? Do you want to use HTTPs for Web Proxy? No
? What is the name of your server? localhost
? What HTTP port do you want to use (all the services are using the same port)? 80
? Do you want to use FTP (port 2121)? No
? Do you want to use MariaDB instead of PostgreSQL? No
? Are you using different languages (this is the most common scenario)? Yes
? Do you want to create an internal SMTP server? No
? Do you want to create an internal LDAP server? No
? Select the addons to be installed:
? Are you using a Windows host to run Docker? No
? Do you want to use a start script? No

In order to restore Postgres dump, we need to start only postgres service.

$ docker-compose up postgres

Once the new database is ready, restore the backup we dumped in the previous section.

$ cat ../alfresco-1/backup/pg-dump.sql | docker-compose exec -T \
postgres psql --username alfresco --password alfresco 

As it has been described above, you can use some other approach in order to restore the Postgres backup. This one is using a plain text file.

Stop again postgres service when the restore is done.

$ docker-compose stop postgres

In order to restore the filesystem, just copy the saved folder to alf-repo-data.

$ cp -r ../alfresco-1/backup/alf-repo-data data/

Finally, SOLR cores backup need to be restored using the expected names (alfresco and archive).

$ mkdir -p data/solr-data/alfresco
$ cp -r ../alfresco-1/backup/solr/alfresco data/solr-data
$ mv data/solr-data/alfresco/snapshot.20210216150258667 data/solr-data/alfresco/index

$ mkdir -p data/solr-data/archive
$ cp -r ../alfresco-1/backup/solr/archive data/solr-data/
$ mv data/solr-data/archive/snapshot.20210216150306103 data/solr-data/archive/index

Folder data should contain following structure after performing these steps.

$ tree -L 2 data
data
├── alf-repo-data
│   ├── contentstore
│   └── contentstore.deleted
├── postgres-data
└── solr-data
    ├── alfresco
    └── archive

Every persisted information is available in the right place at this point, so you can start your ACS in order to check that everything has been restored.

$ docker-compose up --build --force-recreate

Use again Alfresco Share Web Application in order to verify the contents (by default available in http://localhost/share).

About the Author
Angel Borroy is Hyland Developer Evangelist. Over the last 15 years, he has been working as a software architect on Java, BPM, document management and electronic signatures. He has been working with Alfresco during the last years to customize several implementations in large organizations and to provide add-ons to the Community based on Record Management and Electronic Signature. He writes (sometimes) on his personal blog http://angelborroy.wordpress.com. He is (proud) member of the Order of the Bee.
8 Comments