How to backup Redmine using the Bitnami Docker image
In a previous post I detailed how to install Redmine on Linux using the excellent Bitnami docker image.
This post will teach you how to easily make an online backup of your Redmine installation. Note that automating the backup is not within the scope of this post.
We assume that the redmine is installed as shown in my previous post in /var/lib/redmine
. and that you want to backup to my.backup.server:~/redmine-backup/
using rsync
.
Backing up the Redmine data
This is pretty easy, as the data is all in just one directory. You can sync it using
rsync --checksum -Pavz /var/lib/redmine/redmine_data my.backup.server:~/redmine-backup/
Note that old versions of files in redmine_data
will be overwritten, however files that are deleted locally will not be deleted on the backup server. To me, this seems like a good compromise between the ability to recover deleted files and the used storage space.
Backing up the Redmine database
This part is slightly more complicated, since we need to access the MariaDB server running in a different container. *Important note:*The container ID can change so it is not sufficient to just find the container ID once and then use it. You need to determine the appropriate ID each time you do a backup. See below on instructions how to do that.
Full command:
docker exec -it $(docker container ls | grep redmine_mariadb_1 | cut -d' ' -f1) mysqldump -uroot bitnami_redmine | xz -e9 -zc - > redmine-database-dump-$(date -I).sql.xz
Let’s break it down:
docker exec -it (container ID) (command)
: Run a command on a running docker container.docker container ls | grep redmine_mariadb_1 | cut -d' ' -f1
: Get the ID (first field of the outputcut -d' ' -f1
) of the running docker container namedredmine_mariadb_1
mysqldump -uroot bitnami_redmine
: This is run on the docker container and dumps the Redmine Database as SQL to stdout. No password is neccessary since the Bitnami MariaDB image allows access without any password.xz -e9 -zc -
: Takes the data from mysqldump from stdin (-
), compresses it using maximum compression settings (-e9 -z
) and writes the compressed data to stdout.> redmine-database-dump-$(date -I).sql.xz
: Writes the compressed data from xz into a file calledredmine-database-dump-(current date).sql.xz
in the current directory.
The resulting file is called e.g. redmine-database-dump-2019-02-01.sql.xz
and it’s placed in the current directory. Ensure that you run the command in a suitable directory. Run it in /tmp
if you don’t know which directory might be suitable.
Now we can rsync
it to the server:
rsync --checksum -Pavz redmine-backup-*.sql.xz my.backup.server:~/redmine-backup/
Since the filename contains the current data, this approach will not overwrite old daily backups of the database, so you can restore your database very flexibly.