Last active
November 2, 2018 05:48
-
-
Save chux0519/b860b2e1d4efc9a921531cbef55e609b to your computer and use it in GitHub Desktop.
rancher - backup and restore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DATA_PATH=$1 | |
DATE=$(date +%F) | |
BACKUP=rancher-data-backup-$DATE.tar.gz | |
CONTAINER_NAME=$(docker ps | grep rancher | awk '{print $NF}') | |
printf "found running rancher container $CONTAINER_NAME\n" | |
printf "stopping container now...\n" | |
printf "docker stop $CONTAINER_NAME\n" | |
docker stop $CONTAINER_NAME | |
printf "container stoped\n" | |
printf "backing up...\n" | |
printf "tar zcf $BACKUP $DATA_PATH\n" | |
cd $DATA_PATH && cd .. && tar zcf $BACKUP $(basename $DATA_PATH) | |
printf "data backed up\n" | |
printf "restarting container now...\n" | |
printf "docker start $CONTAINER_NAME\n" | |
docker start $CONTAINER_NAME | |
printf "container restrated\n" | |
printf "done\n" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
mkdir -p ./backup | |
tar zxf $1 -C backup |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# backup files named like rancher-data-backup-2018-11-02.tar.gz | |
# keep 5 rotations before deleting | |
ls -1 $1/rancher-data-backup* | sort -r | tail -n +6 | xargs rm -f -- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment