Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JunhongMao committed Oct 3, 2023
1 parent d795b61 commit 85decc9
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions syncd/scripts/saidump.sh
Original file line number Diff line number Diff line change
@@ -1,41 +1,37 @@
#!/bin/bash
set -e

function debug()
save_saidump_by_rdb()
{
/usr/bin/logger "$1"
}

save_saidump_by_rdb() {
local filepath="/var/run/redis/sonic-db/database_config.json"

#Get hostname, port, redis directory
# Get hostname, port, redis directory
local redis_config=$(python3 -c "
import json
with open('$filepath') as json_file:
data = json.load(json_file)
print(data['INSTANCES']['redis']['hostname'], data['INSTANCES']['redis']['port'], data['INSTANCES']['redis']['unix_socket_path'])")

#split
# split
redis_config=(${redis_config// / })
local hostname=${redis_config[0]}
local port=${redis_config[1]}
local redis_dir=`dirname ${redis_config[2]}`
debug "saidump.sh: hostname:$hostname, port:$port, redis_dir:$redis_dir"
logger "saidump.sh: hostname:$hostname, port:$port, redis_dir:$redis_dir"

debug "saidump.sh: [1] Config Redis consistency directory."
logger "saidump.sh: [1] Config Redis consistency directory."
redis-cli -h $hostname -p $port CONFIG SET dir $redis_dir > /dev/null

debug "saidump.sh: [2] SAVE."
logger "saidump.sh: [2] SAVE."
redis-cli -h $hostname -p $port SAVE > /dev/null

debug "saidump.sh: [3] Run rdb command to convert the dump files into JSON files."
logger "saidump.sh: [3] Run rdb command to convert the dump files into JSON files."
rdb --command json $redis_dir/dump.rdb | tee $redis_dir/dump.json > /dev/null

debug "saidump.sh: [4] Run saidump -r to update the JSON files' format as same as the saidump before. Then we can get the saidump's result in standard output."
logger "saidump.sh: [4] Run saidump -r to update the JSON files' format as same as the saidump before. Then we can get the saidump's result in standard output."
saidump -r $redis_dir/dump.json -m 100

debug "saidump.sh: [5] Clear the temporary files."
logger "saidump.sh: [5] Clear the temporary files."
rm -f $redis_dir/dump.rdb
rm -f $redis_dir/dump.json
}
Expand Down

0 comments on commit 85decc9

Please sign in to comment.