Backup and Upgrade Rancher

September 13, 2019

2 min read

Instructions

  1. Setup the following script. We will fill it in going forward
RANCHER_CONTAINER_ID=
RANCHER_CONTAINER_TAG=
URL=rancher.yourdomain.com
TAG=stable

TIMESTAMP() {
  date +%Y-%m-%d_%H-%M-%S
}
  1. SSH into your rancher droplet
ssh [email protected]
  1. Get the CONTAINER_ID by running the command below, and fill it on the script from step 1
docker ps -a
RANCHER_CONTAINER_ID=1cb2c853937b
RANCHER_CONTAINER_TAG=
URL=rancher.yourdomain.com
TAG=stable

TIMESTAMP() {
  date +%Y-%m-%d_%H-%M-%S
}
  1. Go to your installation of rancher at rancher.yourdomain.com and find the rancher version on the bottom left of the screen. Fill this into the script from step 1.
RANCHER_CONTAINER_ID=1cb2c853937b
RANCHER_CONTAINER_TAG=v2.2.4
URL=rancher.yourdomain.com
TAG=stable

TIMESTAMP() {
  date +%Y-%m-%d_%H-%M-%S
}
  1. Go back to your droplet and paste the script we’ve been building

  2. Stop the container currently running rancher

docker stop $RANCHER_CONTAINER_ID
  1. Pull the latest stable version of rancher
docker pull rancher/rancher:$TAG
  1. Create a volume from the rancher container. If you’ve already done this during a earlier upgrade or backup you can skip this step.
docker create --volumes-from $RANCHER_CONTAINER_ID \
--name rancher-data rancher/rancher:$RANCHER_CONTAINER_TAG
  1. Create a backup of your rancher volume into a single file
docker run --volumes-from rancher-data  -v $PWD:/backup alpine tar zcvf /backup/rancher-data-backup-$RANCHER_CONTAINER_TAG-$(TIMESTAMP).tar.gz /var/lib/rancher
  1. Confirm that a new backup files exists with the container tag and timestamp

  2. Start the new version of rancher

docker run -d --volumes-from rancher-data  \
              --restart=unless-stopped -p 80:80 -p 443:443  \
              rancher/rancher:$TAG --acme-domain $URL
  1. Go back into your rancher instance, log back in and confirm that you are running the latest stable version

  2. Remove the old stopped rancher container

docker rm $RANCHER_CONTAINER_ID

Screencast

Resources

Get More!