S
S
Stanislav2019-08-31 12:57:03
MongoDB
Stanislav, 2019-08-31 12:57:03

How to exclude certain collections when creating a database dump?

There is an old script found on the internet that backs up the mongodb database

#!/bin/bash
 
MONGO_DATABASE="collection"
APP_NAME="Name"

MONGO_HOST="127.0.0.1"
MONGO_PORT="27017"
TIMESTAMP=`date +%F-%H%M`
MONGODUMP_PATH="/usr/bin/mongodump"
BACKUPS_DIR="/var/www/backups/$APP_NAME"
BACKUP_NAME="$APP_NAME-$TIMESTAMP"
 
# mongo admin --eval "printjson(db.fsyncLock())"
# $MONGODUMP_PATH -h $MONGO_HOST:$MONGO_PORT -d $MONGO_DATABASE
$MONGODUMP_PATH -d $MONGO_DATABASE
# mongo admin --eval "printjson(db.fsyncUnlock())"
 
mkdir -p $BACKUPS_DIR
mv dump $BACKUP_NAME
tar -zcvf $BACKUPS_DIR/$BACKUP_NAME.tgz $BACKUP_NAME
rm -rf $BACKUP_NAME

find $BACKUPS_DIR -name "*.tgz" -mtime +7 -type f -delete

The problem is that I have resource-intensive collections in which some statistics are collected and I do not need to dump them, just like a collection with sessions, how can I ignore these collections when creating a dump?
sessions
analytics
counts

Or maybe there are some more flexible dump scripts?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saboteur, 2019-08-31
@ms-dred

--excludeCollection <name>
You can list more than one.
ps https://docs.mongodb.com/manual/reference/program/...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question