Description
Possible issue with Restore from Dump
Version: redis-py 5.0.1
Platform: Python 3.11.5 on Ubuntu Server
PRETTY_NAME="Ubuntu 22.04.3 LTS"
NAME="Ubuntu"
VERSION="22.04.3 LTS (Jammy Jellyfish)"
Description: Dump restoration always reports "DUMP payload version or checksum are wrong"
Have tried various versions of redis from 6.x.x to 7.2.x ...... with same results as shown below ...
NOTE: There is only one instance of redis server and on the same machine where this code is being executed from.
CODE SNIPPET START_______
import redis
def dump_redis_db(redis_host, redis_port, redis_password, dump_file_path):
try:
r = redis.Redis(host=redis_host, port=redis_port, password=redis_password)
# Perform a background save (dump) of the Redis database to a file
r.bgsave()
# Wait for the background save to complete
while True:
if r.info('persistence')['rdb_bgsave_in_progress'] == 0:
break
# Copy the generated dump file to the specified path
rdb_file_path = r"/var/lib/redis/dump.rdb"
print(f'{rdb_file_path=}')
with open(rdb_file_path, 'rb') as source, open(dump_file_path, 'wb') as dest:
print(f'{source.read()=}')
dest.write(source.read())
print(f"Redis database dumped to {dump_file_path} successfully.")
except Exception as e:
print(f"An error occurred during dumping: {str(e)}")
def restore_redis_db(redis_host, redis_port, redis_password, dump_file_path):
try:
r = redis.Redis(host=redis_host, port=redis_port, password=redis_password)
r.flushall()
# Restore the Redis database from the dump file
with open(dump_file_path, 'rb') as dump_file:
protocol_dump = dump_file.read()
r.restore('restored_key', 0, protocol_dump)
print("Redis database restored successfully.")
except Exception as e:
print(f"An error occurred during restoration: {str(e)}")
if name == "main":
redis_host = '127.0.0.1'
redis_port = 6379
redis_password = None # Replace with your Redis server password if required
dump_file_path = 'db/redis_dump.rdb' # Replace with the path where you want to save the dump file
# Dump the Redis database to a file
dump_redis_db(redis_host, redis_port, redis_password, dump_file_path)
CODE SNIPPET END_________
Always same result
rdb_file_path='/var/lib/redis/dump.rdb' source.read()=b"REDIS0009\xfa\tredis-ver\x066.2.12\xfa\nredis-bits\xc0@\xfa\x05ctime\xc2\x84\xe2 e\xfa\x08used-mem\xc2\xb8U\r\x00\xfa\x0caof-preamble\xc0\x00\xff\x18u'\x19\xe7U\x92\xf9" Redis database dumped to db/redis_dump.rdb successfully. An error occurred during restoration: DUMP payload version or checksum are wrong