Last active
May 2, 2018 15:51
-
-
Save jeefy/8614deb4d102e4957a858d8dd5f175b0 to your computer and use it in GitHub Desktop.
hateful but sane mongo container backup cron
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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