Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#! /bin/bash
# -- VARS
DAY=`date +"%Y%m%d"`
HOUR=`date +"%H%M"`
BACKUP_PATH=/var/backups/rancher
RANCHER_CONTAINER_ID=rancher_server
RANCHER_HOME=/home/user/rancher
RANCHER_DB_NAME=RANCHER
RANCHER_DB_USER=root
RANCHER_DB_PASS=krnllnx
RANCHER_DB_BACKUP=$RANCHER_HOME/backups/RANCHER_mysql_db.sql
RANCHER_BACKUP_NAME="RANCHER_"$DAY"_"$HOUR".tgz"
RANCHER_BACKUP_HISTO="histo_RANCHER_"$DAY"_"$HOUR".tgz"
RANCHER_BACKUP_LIVE_TIME=10
RANCHER_BACKUP_HISTO_LIVE_TIME=365
MODEL_BKP_DAILY=RANCHER_*.tgz
MODEL_BKP_HISTO=histo_RANCHER_*.tgz
# -- MySQL
echo "Snapshot backuping RANCHER's MySQL db from RANCHER docker instance..."
docker exec -i $RANCHER_CONTAINER_ID mysqldump -A > $RANCHER_DB_BACKUP
echo "($RANCHER_DB_BACKUP) done."
echo
# -- Daily full RANCHER dir backup
echo "Daily backuping RANCHER's directory before sending it to a remote place..."
tar -czvf $BACKUP_PATH/$RANCHER_BACKUP_NAME $RANCHER_HOME
echo "($BACKUP_PATH/$RANCHER_BACKUP_NAME) done."
# -- Monthly full RANCHER dir backup
TOMORROW=`date --date=tomorrow +%d`
if [ $TOMORROW -eq "1" ]; then
echo
echo "End of month : monthly backuping RANCHER's directory..."
cp $BACKUP_PATH/$RANCHER_BACKUP_NAME $BACKUP_PATH/$RANCHER_BACKUP_HISTO
echo "($BACKUP_PATH/$RANCHER_BACKUP_HISTO) done."
fi
# -- Purging old outdated backups
echo
echo "Purging outdated backups..."
find $BACKUP_PATH/$MODEL_BKP_DAILY -mtime +$RANCHER_BACKUP_LIVE_TIME -exec rm {} \;
find $BACKUP_PATH/$MODEL_BKP_HISTO -mtime +$RANCHER_BACKUP_HISTO_LIVE_TIME -exec rm {} \;
echo "done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment