我有一个 redis 容器。我想备份它并在另一个 redis 容器中的另一台机器上重新导入备份。
我按照以下步骤操作:
# Create the original redis container
docker run --name redis -d redis:3.0.3 redis-server --appendonly yes
# add a key inside it for the tests
docker run -it --link redis:redis --rm redis sh -c 'exec redis-cli -h "$REDIS_PORT_6379_TCP_ADDR" -p "$REDIS_PORT_6379_TCP_PORT"'
> SET foo bar
OK
# backup this container
docker run --volumes-from redis -v $(pwd):/backup ubuntu tar cvf /backup/backup.tar /data
# I now have a backup.tar file on my system and I transfer it on another machine
# Recreate a redis container
docker run --name redis2 -d redis:3.0.3 redis-server --appendonly yes
# restore the backup
docker run --volumes-from redis2 -v $(pwd):/backup ubuntu sh -c "cd / && tar xvf /backup/backup.tar"
# check if the backup has been correctly restored
docker run -it --link redis2:redis --rm redis sh -c 'exec redis-cli -h "$REDIS_PORT_6379_TCP_ADDR" -p "$REDIS_PORT_6379_TCP_PORT"'
> GET foo
(nil)
备份未正确恢复。我做错了什么?
最佳答案
我找到了一种方法。
# untar the backup
tar -xvf backup.tar
# create a redis container an mounting the backup as the data folder
docker run --name redis2 -v /home/docker/data:/data -d redis:3.0.3 redis-server --appendonly yes
# test
docker run -it --link redis2:redis --rm redis sh -c 'exec redis-cli -h "$REDIS_PORT_6379_TCP_ADDR" -p "$REDIS_PORT_6379_TCP_PORT"'
> get foo
"bar"
它有效,但感觉“错误”。
关于redis - 如何在redis容器中恢复redis备份?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32091860/