Mongodb: 啓動: /usr/bin/mongod --config /data/mydata/mongodb/mongodb.conf 中止Mongodb: 方法一:$ mongod --shutdown --dbpath 數據路徑 方法二:查看進程,使用kill命令;不能使用kill -9,可用kill -2 或kill-15 方法三:在客戶端進去,使用shutdown命令 > use admin; switched to db admin > db.shutdownServer(); server should be down.. 自動備份腳本: /data/mydata/mongodb/mongodb_bak.sh 配置定時任務:crontab; //mongod.conf: # mongod.conf # for documentation of all options, see: # http://docs.mongodb.org/manual/reference/configuration-options/ # where to write logging data. systemLog: destination: file logAppend: true path: /data/mydata/mongodb/logs/mongodb.log # Where and how to store data. storage: dbPath: /data/mydata/mongodb/db journal: enabled: true # engine: # mmapv1: # wiredTiger: # how the process runs processManagement: fork: true # fork and run in background pidFilePath: /var/run/mongod.pid # location of pidfile # network interfaces net: port: 27017 bindIp: 0.0.0.0 # Listen to local interface only, comment to listen on all interfaces. #security: #operationProfiling: #replication: #sharding: ## Enterprise-Only Options #auditLog: #snmp: //mongodb_bak.sh: #!/bin/bash #backup MongoDB #mongodump命令路徑 DUMP=mongodump #臨時備份目錄 OUT_DIR=/data/mydata/mongodb/bak/bak_tmp #備份存放路徑 TAR_DIR=/data/mydata/mongodb/bak/bak_list #獲取當前系統時間 DATE=`date +%Y_%m_%d` #數據庫帳號 DB_USER= #數據庫密碼 DB_PASS=123 #DAYS=15表明刪除15天前的備份,即只保留近15天的備份 DAYS=15 #最終保存的數據庫備份文件 TAR_BAK="mongodb_bak_$DATE.tar.gz" cd $OUT_DIR rm -rf $OUT_DIR/* mkdir -p $OUT_DIR/$DATE #備份所有數據庫 #$DUMP -h 10.168.1.10:27017 -u $DB_USER -p $DB_PASS --authenticationDatabase "admin" -o $OUT_DIR/$DATE $DUMP -o $OUT_DIR/$DATE #壓縮爲.tar.gz格式 tar -zcvf $TAR_DIR/$TAR_BAK $OUT_DIR/$DATE #刪除15天前的備份文件 find $TAR_DIR/ -mtime +$DAYS -delete exit