Include the MongoDB Docker Container into the Plesk Backup
In a previous post I had already described how MongoDB can be used under Plesk with a Docker container. We had created several volume mappings under a data folder for this purpose. When backing up with Plesk, it can be a problem to back up the contents of the MongoDB Docker container. I would like to suggest solutions for this here.
I have created a new domain for my example domain mongo.example.com
First, I switched off the container and then copied all files to the directory of my new Plesk domain
sudo cp -a /data /var/www/vhosts/mongo.example.com/Then I adjusted the volume mapping in Plesk accordingly

and restarted my container with the name mongo.
Then I created a new folder databackup in the Plesk File Manager in the home directory of mongo.example.com.
The next step is to secure the MongoDB database correctly, and the container should ideally be switched off for this. The file permissions should also be retained. I have therefore decided to use a tar archive and to stop and restart the container automatically.
sudo bash -c 'docker stop mongo && TS=$(date %Y%m%d) && BACKUP="/var/www/vhosts/mongo.licenseplate.ae/databackup/mongo_backup_${TS}.tar.gz" && tar -cvpzf "$BACKUP" -C /var/www/vhosts/mongo.licenseplate.ae data && chown psaadm:psaadm "$BACKUP" && docker start mongo'Of course, this would be much better as a cronjob in Plesk, but Plesk is bothered by the numerous quotation marks.
That’s why I have under /root/ with
cd /root/
nano mongobackup.sh
to create a new file with the following content
#!/bin/bash
docker stop mongo
TS=$(date %Y%m%d)
BACKUP="/var/www/vhosts/mongo.example.com/databackup/mongo_backup_${TS}.tar.gz"
tar -cvpzf "$BACKUP" -C /var/www/vhosts/mongo.example.com data
chown psaadm:psaadm "$BACKUP"
docker start mongoand then make the file executable
chmod x mongobackup.shNow you can simply add a cronjob in the Plesk task manager of the server for the command /root/mongobackup.sh
I have selected a daily execution at 1 o’clock.
What exactly happens now?
The MongoContainer is stopped. All data of the Docker container is backed up as a tar archive with file permissions. To avoid problems, the owner of the file is subsequently changed so that the Plesk backup manager also has access. The MongoContainer is restarted. The Plesk backup will automatically back up all files in the home of mongo.example.com (as with other domains) and thus the tar archives will also be available in the backup later.
Of course, the data directory does not necessarily have to be moved to the home of mongo.example.com. However, the databackup directory should always be located under a domain (so that it is automatically included in the Plesk backup).
If all this is too complicated for you, you are welcome to hire me at a reasonable hourly rate.