Moodle Backup and Restore in Docker
Backup moodle & mariadb images to a folder
First, Run the docker commit container command this is just for copying the container image (where moodle-moodle-1 & moodle-mariadb-1 is the name of the constainer try: "docker ps" to look for the name of that container you want to commit) :
# docker commit -p moodle-moodle-1 backup-moodle-moodle-1
# docker commit -p moodle-mariadb-1 backup-moodle-mariadb-1- Alternatively, we can save it as a tar file in any directory and move it freely to any desired docker host system for a deployment:
# docker save -o ~/backup-moodle-moodle-1.tar backup-moodle-moodle-1
# docker save -o ~/backup-moodle-mariadb-1.tar backup-moodle-mariadb-1
- Backing up Docker volumes to a folder
# docker volume ls
- Secondly , Backup the data in the docker volumes into a compressed file archive and save it to the local directory /tmp or any directory you want (just change only the /tmp to any directory you want) the mariadb_data, moodle_data, moodledata_data are the volumes so write according to the name of the volumes:
# docker run --rm -v mariadb_data:/bitnami/mariadb -v /tmp/:/backup ubuntu tar -czvf /backup/mysql-backup.tar.gz /bitnami/mariadb
# docker run --rm -v moodle_data:/bitnami/moodle -v /tmp/:/backup ubuntu tar -czvf /backup/moodle-backup.tar.gz /bitnami/moodle
# docker run --rm -v moodledata_data:/bitnami/moodledata -v /tmp/:/backup ubuntu tar -czvf /backup/moodle-data-backup.tar.gz /bitnami/moodledata
# docker run --rm -v moodle_data:/bitnami/moodle -v /tmp/:/backup ubuntu tar -czvf /backup/moodle-backup.tar.gz /bitnami/moodle
# docker run --rm -v moodledata_data:/bitnami/moodledata -v /tmp/:/backup ubuntu tar -czvf /backup/moodle-data-backup.tar.gz /bitnami/moodledata
Restore moodle & mariadb (container + data volume)
First, load the image from the previous backup archive file so that the container can be created :
# docker load -i backup-moodle-moodle-1.tar
docker load -i backup-moodle-mariadb-1.tar
docker images
Second, restore the backup data volume from the archive file into a new Docker volume, create a new Docker volume, and then restore the data from the archive file into the newly created Docker volume :
# docker volume create moodle_mariadb_data
# docker volume create moodle_moodle_data
# docker volume create moodle_moodledata_data
# docker run --rm -v moodle_mariadb_data:/bitnami/mariadb -v /tmp:/backup ubuntu tar -xvzf /backup/mysql-backup.tar.gz -C /
# docker run --rm -v moodle_moodle_data:/bitnami/moodle -v /tmp:/backup ubuntu tar -xvzf /backup/moodle-backup.tar.gz -C /
# docker run --rm -v moodle_moodledata_data:/bitnami/moodledata -v /tmp:/backup ubuntu tar -xvzf /backup/moodle-data-backup.tar.gz -C /
# docker volume create moodle_moodle_data
# docker volume create moodle_moodledata_data
# docker run --rm -v moodle_mariadb_data:/bitnami/mariadb -v /tmp:/backup ubuntu tar -xvzf /backup/mysql-backup.tar.gz -C /
# docker run --rm -v moodle_moodle_data:/bitnami/moodle -v /tmp:/backup ubuntu tar -xvzf /backup/moodle-backup.tar.gz -C /
# docker run --rm -v moodle_moodledata_data:/bitnami/moodledata -v /tmp:/backup ubuntu tar -xvzf /backup/moodle-data-backup.tar.gz -C /
Third, edit the Docker Compose file used at the beginning. Note that in this new Docker Compose file, we will be using the existing Docker volume that has been filled with data from the previous restoration process (Better to edit the old docker compose file and try to copy from the old and mix with this in order to run properly without errors)
version: '2'
services:
mbda_mariadb:
image: backup-mariadb
environment:
# ALLOW_EMPTY_PASSWORD is recommended only for development.
- ALLOW_EMPTY_PASSWORD=yes
- MARIADB_USER=bn_moodle
- MARIADB_DATABASE=bitnami_moodle
- MARIADB_CHARACTER_SET=utf8mb4
- MARIADB_COLLATE=utf8mb4_unicode_ci
volumes:
- 'mariadb_data:/bitnami/mariadb'
#ports:
#- '3307:3306'
mbda_moodle:
image: backup-moodle
ports:
- '8000:8080'
- '8001:8443'
environment:
- MOODLE_DATABASE_HOST=mbda_mariadb
- MOODLE_DATABASE_PORT_NUMBER=3306
- MOODLE_DATABASE_USER=bn_moodle
- MOODLE_DATABASE_NAME=bitnami_moodle
# ALLOW_EMPTY_PASSWORD is recommended only for development.
- ALLOW_EMPTY_PASSWORD=yes
volumes:
- 'moodle_data:/bitnami/moodle'
- 'moodledata_data:/bitnami/moodledata'
depends_on:
- mbda_mariadb
volumes:
mariadb_data:
external: true
name: moodle_mariadb_data
moodle_data:
external: true
name: moodle_moodle_data
moodledata_data:
external: true
name: moodle_moodledata_data
Finally, we just need to run docker-compose up, then verify that the Moodle application is running and all the stored data is still intact.
Commands to Troubleshoot
Check for process all
docker ps -a
docker ps -a -f status=exited (to list all container that is stop)
To Stop/Remove a container
docker stop <container-name>
docker rm <container-name>
To check for Logs for a container (pass -f to not stop):
docker logs <container-name>
To check/remove/inspect for a network :
docker network ls
docker network rm <network-name>
docker network inspect <network-name>
Comments
Post a Comment