我有一个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)
备份未正确恢复.我究竟做错了什么?
最佳答案
我找到了办法.
原文链接:https://www.f2er.com/docker/436636.html# 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"
它有效,但感觉“错误”.