I have a redis container. I would like to back it up and reimport the backup on another machine in another redis container.
I followed theses steps:
# 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)
The backup is not restored properly. What am I doing wrong?
I found a way to do it.
# 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"
It works but it feels "wrong".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With