Skip to content

Simply script to backup/restore mongo db with json file

Notifications You must be signed in to change notification settings

PitayaX/MongoSync

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 

Repository files navigation

OverView

This is simply python script to backup/restore mongodb with json config

Usage

To backup database we can use following syntax

python mongo_sync.py -config config.json

or restore a database from local folder

python mongo_sync.py -r -config config.json

Arguments

  • -config configfile

It use named configuration file that include server and mongo program info

  • -restore or -r

This flag used for restore mode, default is backup mode without this flag

JSON format

{
	"servers":{
		//Used server arguments in command line
		"arguments":["host", "port", "username", "password"],	
		//The source mongodb server used for backup
		"source":{												
			"host": "xxx.xxx.xxx.xxx",
			"port": "27017",
			"username": "",
			"password":"",
			"authenticationDatabase":"",
			"databases":["db1", "db2"]
		},
		//The target mongodb server used for restore.
		//It will use source server item for restore if it doesn't exist.
		"target":{												
			"host": "xxx.xxx.xxx.xxx",							
			"port": "27017",
			"username": "",
			"password":"",
			"authenticationDatabase":"",
			"databases":"db1"
		}
	},
	//This script use mongodump and mongorestore to backup/restore, We must set the program path of them
	"programs":{										
		"dump":"...\\mongodb\\mongodump.exe",
		"restore":"...\\mongodb\\mongorestore.exe"
	},
	//Output folder backup/restore, it support date flag
	"output":"..\\backup\\{$today:%Y%m%d}\\"
}

About

Simply script to backup/restore mongo db with json file

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%