按照文档进行的操作
创建rancher命令
docker run -d --restart=unless-stopped \
-p 80:80 \
-p 443:443 \
-v /data/rancher/db:/var/lib/rancher \
--privileged \
--name rancher \
-e TZ=Asia/Shanghai \
-e AUDIT_LEVEL=3 \
-e CATTLE_SYSTEM_DEFAULT_REGISTRY="repo.yousen.plus" \
-e CATTLE_SYSTEM_CATALOG=bundled \
rancher/rancher:latest
备份脚本
#!/bin/bash
# 设置变量
RANCHER_VERSION="latest"
RANCHER_CONTAINER_NAME="rancher"
DATE=$(date +%Y-%m-%d)
docker stop $RANCHER_CONTAINER_NAME
# 创建一个新的只读容器用于备份数据
docker create --volumes-from "$RANCHER_CONTAINER_NAME" \
--name "rancher-data-$DATE" \
rancher/rancher:$RANCHER_VERSION
# 执行备份操作
docker run --name "busybox-backup-$DATE" \
--volumes-from "rancher-data-$DATE" \
-v "$PWD:/backup:z" \
busybox tar pzcvf "/backup/rancher-data-backup-$RANCHER_VERSION-$DATE.tar.gz" /var/lib/rancher
docker rm "rancher-data-$DATE"
docker rm "busybox-backup-$DATE"
docker start $RANCHER_CONTAINER_NAME
恢复脚本
#!/bin/bash
RANCHER_CONTAINER_NAME="rancher"
RANCHER_VERSION="latest"
DATE=$(date +%Y-%m-%d)
# 停止 Rancher 容器
docker stop "$RANCHER_CONTAINER_NAME"
# 使用临时容器挂载源容器的数据卷,并从备份中解压数据
docker run --rm --volumes-from "$RANCHER_CONTAINER_NAME" -v "$PWD:/backup" \
busybox sh -c "rm -rf /var/lib/rancher/* && \
tar pzxvf /backup/rancher-data-backup-$RANCHER_VERSION-$DATE.tar.gz -C /var/lib/rancher/"
# 启动 Rancher 容器
docker start "$RANCHER_CONTAINER_NAME"
恢复后报错