Skip to content

Instantly share code, notes, and snippets.

@jeefy
Last active May 2, 2018 15:51
Show Gist options
  • Save jeefy/8614deb4d102e4957a858d8dd5f175b0 to your computer and use it in GitHub Desktop.
Save jeefy/8614deb4d102e4957a858d8dd5f175b0 to your computer and use it in GitHub Desktop.
hateful but sane mongo container backup cron
#!/bin/bash
containers=$(sudo docker ps | grep mongo | awk '{if(NR>1) print $NF}')
timestamp=$(date +%Y-%m-%d_%H-%M-%S)
backup_command="mongodump --gzip --archive=/data/db/$timestamp.tar.gz"
prune_command="find /data/db/ -type f -mtime +7 -name '*.gz' -execdir rm -- '{}' \;"
for container in $containers
do
echo $container
echo $backup_command
docker exec $container /bin/sh -c "$backup_command"
echo $prune_command
docker exec $container /bin/sh -c "$prune_command"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment