|
1 | 1 | #!/bin/bash
|
2 | 2 | set -e
|
3 | 3 |
|
4 |
| -function debug() |
| 4 | +save_saidump_by_rdb() |
5 | 5 | {
|
6 |
| - /usr/bin/logger "$1" |
7 |
| -} |
8 |
| - |
9 |
| -save_saidump_by_rdb() { |
10 | 6 | local filepath="/var/run/redis/sonic-db/database_config.json"
|
11 | 7 |
|
12 |
| - #Get hostname, port, redis directory |
| 8 | + # Get hostname, port, redis directory |
13 | 9 | local redis_config=$(python3 -c "
|
14 | 10 | import json
|
15 | 11 | with open('$filepath') as json_file:
|
16 | 12 | data = json.load(json_file)
|
17 | 13 | print(data['INSTANCES']['redis']['hostname'], data['INSTANCES']['redis']['port'], data['INSTANCES']['redis']['unix_socket_path'])")
|
18 | 14 |
|
19 |
| - #split |
| 15 | + # split |
20 | 16 | redis_config=(${redis_config// / })
|
21 | 17 | local hostname=${redis_config[0]}
|
22 | 18 | local port=${redis_config[1]}
|
23 | 19 | local redis_dir=`dirname ${redis_config[2]}`
|
24 |
| - debug "saidump.sh: hostname:$hostname, port:$port, redis_dir:$redis_dir" |
| 20 | + logger "saidump.sh: hostname:$hostname, port:$port, redis_dir:$redis_dir" |
25 | 21 |
|
26 |
| - debug "saidump.sh: [1] Config Redis consistency directory." |
| 22 | + logger "saidump.sh: [1] Config Redis consistency directory." |
27 | 23 | redis-cli -h $hostname -p $port CONFIG SET dir $redis_dir > /dev/null
|
28 | 24 |
|
29 |
| - debug "saidump.sh: [2] SAVE." |
| 25 | + logger "saidump.sh: [2] SAVE." |
30 | 26 | redis-cli -h $hostname -p $port SAVE > /dev/null
|
31 | 27 |
|
32 |
| - debug "saidump.sh: [3] Run rdb command to convert the dump files into JSON files." |
| 28 | + logger "saidump.sh: [3] Run rdb command to convert the dump files into JSON files." |
33 | 29 | rdb --command json $redis_dir/dump.rdb | tee $redis_dir/dump.json > /dev/null
|
34 | 30 |
|
35 |
| - 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." |
| 31 | + 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." |
36 | 32 | saidump -r $redis_dir/dump.json -m 100
|
37 | 33 |
|
38 |
| - debug "saidump.sh: [5] Clear the temporary files." |
| 34 | + logger "saidump.sh: [5] Clear the temporary files." |
39 | 35 | rm -f $redis_dir/dump.rdb
|
40 | 36 | rm -f $redis_dir/dump.json
|
41 | 37 | }
|
|
0 commit comments