flake8: E501 line too long (N > 79 characters).

This commit is contained in:
Bas Couwenberg
2019-05-02 11:08:23 +02:00
committed by Dan Christian Bogos
parent c591f3e51c
commit 14db4adf83
4 changed files with 100 additions and 28 deletions

View File

@@ -3,8 +3,9 @@
# depends:
# ^ 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
# ^ 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
import subprocess
import sys
@@ -33,7 +34,8 @@ ignore_empty_cols = True
# Overwrite target collections flag.
# Works only if from/to is on same host.
# If from/to hosts are different we use mongorestore which overwrites by default.
# If from/to hosts are different we use mongorestore
# which overwrites by default.
drop_target = False
dump_folder = 'dump'
@@ -41,9 +43,19 @@ dump_folder = 'dump'
# same server
if from_host == to_host and from_port == to_port:
print('Migrating on same server...')
mongo_from_url = 'mongodb://' + from_user + ':' + quote_plus(from_pass) + '@' + from_host + ':' + from_port + '/' + from_auth_db
mongo_from_url = 'mongodb://%s:%s@%s:%s/%s' % (
from_user,
quote_plus(from_pass),
from_host,
from_port,
from_auth_db
)
if from_pass == '': # disabled auth
mongo_from_url = 'mongodb://' + from_host + ':' + from_port + '/' + from_db
mongo_from_url = 'mongodb://%s:%s/%s' % (
from_host,
from_port,
from_db
)
client = MongoClient(mongo_from_url)
db = client[from_db]
@@ -55,15 +67,43 @@ if from_host == to_host and from_port == to_port:
i = 0
for col in cols:
i += 1
if not ignore_empty_cols or (ignore_empty_cols and db[col].count() > 0):
print('Moving collection %s (%d of %d)...' % (col, i, len(cols)))
if(
not ignore_empty_cols or
(ignore_empty_cols and db[col].count() > 0)
):
print(
'Moving collection %s (%d of %d)...' % (
col, i, len(cols)
)
)
try:
client.admin.command(OrderedDict([('renameCollection', from_db + '.' + col), ('to', to_db + '.' + col), ('dropTarget', drop_target)]))
client.admin.command(
OrderedDict(
[
(
'renameCollection',
from_db + '.' + col
),
(
'to',
to_db + '.' + col
),
(
'dropTarget',
drop_target
)
]
)
)
except:
e = sys.exc_info()[0]
print(e)
else:
print('Skipping empty collection %s (%d of %d)...' % (col, i, len(cols)))
print(
'Skipping empty collection %s (%d of %d)...' % (
col, i, len(cols)
)
)
# no collections found
else:
print('No collections in source database.')

View File

@@ -3,8 +3,8 @@
# depends:
# ^ 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)
# ^ destination redis is not password protected when connected from source
# redis server (https://github.com/antirez/redis/pull/2507)
# behaviour:
# ^ the script will not overwrite keys on the destination server/database
@@ -23,8 +23,17 @@ to_pass = '' # Not used
keymask = '*'
timeout = 2000
from_redis = redis.Redis(host=from_host, port=from_port, password=from_pass, db=from_db)
to_redis = redis.Redis(host=to_host, port=to_port, db=to_db)
from_redis = redis.Redis(
host=from_host,
port=from_port,
password=from_pass,
db=from_db
)
to_redis = redis.Redis(
host=to_host,
port=to_port,
db=to_db
)
to_keys = to_redis.keys(keymask)
from_keys = from_redis.keys(keymask)
@@ -50,7 +59,14 @@ if len(from_keys) > 0:
i += 1
print('Moving key %s (%d of %d)...' % (key, i, len(from_keys))),
try:
from_redis.execute_command('MIGRATE', to_host, to_port, key, to_db, timeout)
from_redis.execute_command(
'MIGRATE',
to_host,
to_port,
key,
to_db,
timeout
)
except redis.exceptions.ResponseError as e:
if 'ERR Target key name is busy' not in str(e):
raise e

View File

@@ -12,11 +12,11 @@ user = 'root'
password = 'CGRateS.org'
config = {
'user': user,
'password': password,
'host': host,
'port': port,
'database': database,
'user': user,
'password': password,
'host': host,
'port': port,
'database': database,
}
print('Connecting to MySQL...')
@@ -24,13 +24,24 @@ cnx = mysql.connector.connect(**config)
cursor = cnx.cursor()
print('Renaming old column...')
cursor.execute('ALTER TABLE cdrs CHANGE COLUMN `usage` `usage_old` DECIMAL(30,9)')
cursor.execute(
(
'ALTER TABLE cdrs'
' CHANGE COLUMN `usage` `usage_old`'
' DECIMAL(30,9)'
)
)
print('Adding new column...')
cursor.execute('ALTER TABLE cdrs ADD `usage` DECIMAL(30)')
print('Setting new values...')
cursor.execute('UPDATE cdrs SET `usage` = `usage_old` * 1000000000 WHERE usage_old IS NOT NULL')
cursor.execute(
(
'UPDATE cdrs SET `usage` = `usage_old` * 1000000000'
' WHERE usage_old IS NOT NULL'
)
)
print('Deleting old column...')
cursor.execute('ALTER TABLE cdrs DROP COLUMN usage_old')

View File

@@ -13,12 +13,12 @@ password = 'CGRateS.org'
print('Connecting to PostgreSQL...')
cnx = psycopg2.connect(
host=host,
port=port,
dbname=database,
user=user,
password=password
)
host=host,
port=port,
dbname=database,
user=user,
password=password
)
cursor = cnx.cursor()
print('Renaming old column...')
@@ -28,7 +28,12 @@ print('Adding new column...')
cursor.execute('ALTER TABLE cdrs ADD usage NUMERIC(30)')
print('Setting new values...')
cursor.execute('UPDATE cdrs SET usage = usage_old * 1000000000 WHERE usage_old IS NOT NULL')
cursor.execute(
(
'UPDATE cdrs SET usage = usage_old * 1000000000'
' WHERE usage_old IS NOT NULL'
)
)
print('Deleting old column...')
cursor.execute('ALTER TABLE cdrs DROP COLUMN usage_old')