-
Notifications
You must be signed in to change notification settings - Fork 650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MultiDB] add MultiDB warmboot support - backing up database #1205
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -247,10 +247,14 @@ function backup_database() | |
end | ||
end | ||
" 0 > /dev/null | ||
sonic-db-cli SAVE > /dev/null | ||
#TODO : need a script to copy all rdb files if there is multiple db instances config | ||
docker cp database:/var/lib/redis/$REDIS_FILE $WARM_DIR | ||
docker exec -i database rm /var/lib/redis/$REDIS_FILE | ||
|
||
# move all db data into instances where APPL_DB locates | ||
migrate_warmboot_database APPL_DB | ||
|
||
inst=`/usr/bin/python -c "import swsssdk; print(swsssdk.SonicDBConfig.get_instancename('APPL_DB'))"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Instead of using a new process to locate APPL_DB, you may just print it to stdout in above command. #Closed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
# Dump redis content to a file 'dump.rdb' in warmboot directory | ||
docker cp database:/var/lib/$inst/$REDIS_FILE $WARM_DIR | ||
docker exec -i database rm /var/lib/$inst/$REDIS_FILE | ||
} | ||
|
||
function setup_control_plane_assistant() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/python | ||
from __future__ import print_function | ||
import sys | ||
import swsssdk | ||
import redis | ||
import argparse | ||
|
||
def migrate(target_dbname): | ||
target_dbport = swsssdk.SonicDBConfig.get_port(target_dbname) | ||
target_dbhost = swsssdk.SonicDBConfig.get_hostname(target_dbname) | ||
|
||
dblists = swsssdk.SonicDBConfig.get_dblist() | ||
for dbname in dblists: | ||
dbport = swsssdk.SonicDBConfig.get_port(dbname) | ||
# if the db is on the same instance, no need to migrate | ||
if dbport == target_dbport: | ||
continue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it enough to determine "the same instance" ? #Closed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch. hostname plus port is enough to determine the "unique instance" . Updated |
||
|
||
dbsocket = swsssdk.SonicDBConfig.get_socket(dbname) | ||
dbid = swsssdk.SonicDBConfig.get_dbid(dbname) | ||
dbhost = swsssdk.SonicDBConfig.get_hostname(dbname) | ||
|
||
r = redis.Redis(host=dbhost, unix_socket_path=dbsocket, db=dbid) | ||
|
||
script = """ | ||
local cursor = 0; | ||
repeat | ||
local dat = redis.call('SCAN', cursor, 'COUNT', 7000); | ||
cursor = dat[1]; | ||
redis.call('MIGRATE', KEYS[1], KEYS[2], '', KEYS[3], 5000, 'COPY', 'REPLACE', 'KEYS', unpack(dat[2])); | ||
until cursor == '0'; | ||
""" | ||
r.eval(script, 3, target_dbhost, target_dbport, dbid) | ||
|
||
#SAVE rdb file | ||
r = redis.Redis(host=target_dbhost, port=target_dbport) | ||
r.save() | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description='migrate all db data into one db instances', | ||
formatter_class=argparse.RawTextHelpFormatter, | ||
epilog= | ||
""" | ||
Example : migrate_warmboot_database APPL_DB | ||
""") | ||
parser.add_argument('target_db', type=str, help='move all db data into the instance where target db locates') | ||
args = parser.parse_args() | ||
|
||
if args.target_db: | ||
try: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
too much indentation. #Closed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
migrate(args.target_db) | ||
except Exception as ex: | ||
template = "An exception of type {0} occurred. Arguments:\n{1!r}" | ||
message = template.format(type(ex).__name__, ex.args) | ||
print(message, file=sys.stderr) | ||
sys.exit(1) | ||
else: | ||
parser.print_help() | ||
|
||
if __name__ == "__main__": | ||
main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name is misleading. It is not directly related to warmboot.
Suggestion
centralize_database
#Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated