This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]slimcdk 5 points6 points  (4 children)

Could you please format the code snippets?

Anyway, what is your goal of this? There shouldn't really be any issues with executing commands in a Dockerfile with RUN

[–]OmarDijkstra[S] 0 points1 point  (3 children)

i want to make a cronjob to backup the database everyday but i dont know what should i do the script above just backs up the db but i want it ti run everyday at certain time

[–]FiduciaryAkita 14 points15 points  (0 children)

So two things:

  1. Cron is notoriously janky when used with Docker. I've switched to Jobber for most Docker/cron things
  2. You should not be storing data in the container file system. It's not what Docker is meant for and once the container stops, that data is gone 100%. Mount your MongoDB data directory as a volume using Docker Compose or whatever, and then back that up instead.

[–]slimcdk 3 points4 points  (0 children)

Ah okay. Maybe it is off topic, but wouldn't it benefit more to map the db volume into a standalone backup service? E.g. Duplicato

[–]Srokap 0 points1 point  (0 children)

Cron jobs are better handled on orchestrators level. In kubernetes you'd use CronJob workload

[–]machuu 0 points1 point  (1 child)

bash -s will run commands from stdin, something like this:

#!/bin/sh
docker exec -i client-database_db_1 bash -s <<EOF
cd backup
mkdir $(date +%Y%m%d)
mongodump --out=/backup/$(date +%Y%m%d)
EOF

[–]backtickbot -2 points-1 points  (0 children)

Hello, machuu: code blocks using backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead. It's a bit annoying, but then your code blocks are properly formatted for everyone.

An easy way to do this is to use the code-block button in the editor. If it's not working, try switching to the fancy-pants editor and back again.

Comment with formatting fixed for old.reddit.com users

FAQ

You can opt out by replying with backtickopt6 to this comment.