From 6c79d9717b6d06564db2d56e4325e39ea2ad04f9 Mon Sep 17 00:00:00 2001 From: DanB Date: Mon, 10 Apr 2017 16:17:14 +0200 Subject: [PATCH] DataDB default name to 10, dbsmerge small corrections --- config/config_defaults.go | 2 +- config/config_json_test.go | 2 +- config/config_test.go | 2 +- data/conf/cgrates/cgrates.json | 2 +- data/scripts/migrator/dbsmerge_mongo.py | 21 ++++++++++++--------- data/scripts/migrator/dbsmerge_redis.py | 8 ++++---- 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/config/config_defaults.go b/config/config_defaults.go index 6b2f8b067..3c3dcad2c 100644 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -87,7 +87,7 @@ const CGRATES_CFG_JSON = ` "db_type": "redis", // data_db type: "db_host": "127.0.0.1", // data_db host address "db_port": 6379, // data_db port to reach the database - "db_name": "11", // data_db database name to connect to + "db_name": "10", // data_db database name to connect to "db_user": "", // username to use when connecting to data_db "db_password": "", // password to use when connecting to data_db "load_history_size": 10, // Number of records in the load history diff --git a/config/config_json_test.go b/config/config_json_test.go index 20583273d..06087de28 100644 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -122,7 +122,7 @@ func TestDfDbJsonCfg(t *testing.T) { Db_type: utils.StringPointer("redis"), Db_host: utils.StringPointer("127.0.0.1"), Db_port: utils.IntPointer(6379), - Db_name: utils.StringPointer("11"), + Db_name: utils.StringPointer("10"), Db_user: utils.StringPointer(""), Db_password: utils.StringPointer(""), Load_history_size: utils.IntPointer(10), diff --git a/config/config_test.go b/config/config_test.go index 19f311994..c2b425450 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -217,7 +217,7 @@ func TestCgrCfgJSONDefaultsjsnDataDb(t *testing.T) { if cgrCfg.DataDbPort != "6379" { t.Error(cgrCfg.DataDbPort) } - if cgrCfg.DataDbName != "11" { + if cgrCfg.DataDbName != "10" { t.Error(cgrCfg.DataDbName) } if cgrCfg.DataDbUser != "" { diff --git a/data/conf/cgrates/cgrates.json b/data/conf/cgrates/cgrates.json index 1e3f6c51a..cf03f6f07 100644 --- a/data/conf/cgrates/cgrates.json +++ b/data/conf/cgrates/cgrates.json @@ -67,7 +67,7 @@ // "db_type": "redis", // data_db type: // "db_host": "127.0.0.1", // data_db host address // "db_port": 6379, // data_db port to reach the database -// "db_name": "11", // data_db database name to connect to +// "db_name": "10", // data_db database name to connect to // "db_user": "", // username to use when connecting to data_db // "db_password": "", // password to use when connecting to data_db // "load_history_size": 10, // Number of records in the load history diff --git a/data/scripts/migrator/dbsmerge_mongo.py b/data/scripts/migrator/dbsmerge_mongo.py index 8c15f33ec..b1e916e48 100755 --- a/data/scripts/migrator/dbsmerge_mongo.py +++ b/data/scripts/migrator/dbsmerge_mongo.py @@ -1,24 +1,22 @@ #!/usr/bin/python # depends: -# ^ pymongo -# asserts: -# ^ destination mongo database exists and the destination user can auth on it +# ^ pymongo # install via: easy_install pymongo # behaviour: # ^ the script will "move" the collections if source and target server are the same # but will "copy" (dump/restore) if source and target servers are different from_host = '127.0.0.1' from_port = '27017' -from_db = 'cgrates2' +from_db = '11' from_user = 'cgrates' -from_pass = 'CGRateS.org' +from_pass = '' to_host = '127.0.0.1' to_port = '27017' -to_db = 'cgrates2' +to_db = '10' to_user = 'cgrates' -to_pass = 'CGRateS.org' +to_pass = '' dump_folder = 'dump' @@ -27,6 +25,8 @@ from urllib import quote_plus from collections import OrderedDict mongo_from_url = 'mongodb://' + from_user + ':' + quote_plus(from_pass) + '@'+ from_host + ':' + from_port + '/' + from_db +if from_pass == '': # disabled auth + mongo_from_url = 'mongodb://' + from_host + ':' + from_port + '/' + from_db client = MongoClient(mongo_from_url) db = client[from_db] @@ -39,10 +39,13 @@ if len(cols) > 0: print('Migrating on same server...') print('Found %d collections on source. Moving...' % len(cols)) i = 0 - for col in db.collection_names(): + for col in cols: i += 1 print('Moving colection %s (%d of %d)...' % (col, i, len(cols))) - client.admin.command(OrderedDict([('renameCollection', from_db + '.' + col), ('to', to_db + '.' + col)])) + try: + client.admin.command(OrderedDict([('renameCollection', from_db + '.' + col), ('to', to_db + '.' + col)])) + except: + continue # different servers else: import subprocess diff --git a/data/scripts/migrator/dbsmerge_redis.py b/data/scripts/migrator/dbsmerge_redis.py index ca491d0a0..907f89483 100755 --- a/data/scripts/migrator/dbsmerge_redis.py +++ b/data/scripts/migrator/dbsmerge_redis.py @@ -1,7 +1,7 @@ #!/usr/bin/python # depends: -# ^ redis +# ^ redis # install via easy_install redis # asserts: # ^ destination redis is not password protected when connected from source redis server # (https://github.com/antirez/redis/pull/2507) @@ -10,12 +10,12 @@ from_host = '127.0.0.1' from_port = 6379 -from_db = 0 +from_db = 11 from_pass = '' to_host = '127.0.0.1' -to_port = 6380 -to_db = 0 +to_port = 6379 +to_db = 10 to_pass = '' # Not used keymask = '*'