Update nodemgmt-scripts.sh

This commit is contained in:
2019-01-27 16:42:51 -06:00
parent 2601e862c5
commit 464e9259d4

View File

@@ -64,134 +64,184 @@ MAIN_MENU() {
done done
} }
case $1 in case "$1" in
'backup')
if [ "$BASE_BACKUP" = "" ]; then
$0 backup-base
else
$0 backup-incremental
fi
allfiles=`ls -1 ${BACKUP_PATH}` start)
files=(`ls -1 ${BACKUP_PATH} | tail -${BACKUPSTOKEEP}`) sleep 15
for i in $allfiles; do echo -e "${BBlue}HAProxy Starting...${Color_Off}"
keep=0; service haproxy start
for a in ${files[@]}; do ssh root@10.5.10.52 service haproxy start
if [ $i == $a ]; then ssh root@10.5.10.53 service haproxy start
keep=1; echo -e "${BBlue}NGINX Reload...${Color_Off}"
fi; service nginx reload
done; ssh root@10.5.10.52 service nginx reload
if [ $keep == 0 ]; then ssh root@10.5.10.53 service nginx reload
rm -rf ${BACKUP_PATH}$i;
fi;
done
;;
'backup-base')
DEST_DIR="${DAY_BACKUP_DIR}`date +%H-%M-%S`_BASE"
if [ "$BASE_BACKUP" != "" ]; then exit 0
echo -e "${idsCL[Green]}Daily base backup already done. Running incremental backup...${idsCL[Default]}" ;;
sleep 3
$0 backup-incremental
exit 1
fi
if [ ! -d "$DAY_BACKUP_DIR" ]; then stop)
mkdir -p "$DAY_BACKUP_DIR" echo -e "${BBlue}HAProxy Stopping...${Color_Off}"
fi service haproxy stop
ssh root@10.5.10.52 service haproxy stop
ssh root@10.5.10.53 service haproxy stop
exit 0;;
# innobackupex --defaults-file="$MYSQLCFG" --user="$MYSQLUSER" --password="$MYSQLPASS" --no-timestamp "$DEST_DIR" gogs-start)
mariabackup --backup --target-dir="$DEST_DIR" --user="$MYSQLUSER" --password="$MYSQLPASS" echo -e "${BBlue}Gogs Starting...${Color_Off}"
;; service gogs start
'backup-incremental') ssh root@10.5.10.52 service gogs start
DEST_DIR="${DAY_BACKUP_DIR}`date +%H-%M-%S`" ssh root@10.5.10.53 service gogs start
exit 0;;
if [ "$BASE_BACKUP" = "" ]; then gogs-stop)
echo -e "${idsCL[Green]}Daily base backup not found. Running base backup...${idsCL[Default]}" echo -e "${BBlue}Gogs Stopping...${Color_Off}"
$0 backup-base service gogs stop
exit 1 ssh root@10.5.10.52 service gogs stop
fi ssh root@10.5.10.53 service gogs stop
exit 0;;
#innobackupex --defaults-file="$MYSQLCFG" --user="$MYSQLUSER" --password="$MYSQLPASS" \ gogs-restart)
#--incremental-basedir="${DAY_BACKUP_DIR}${BASE_BACKUP}" \ echo -e "${BBlue}Gogs Restarting...${Color_Off}"
#--incremental "$DEST_DIR" \ service gogs restart
#--no-timestamp ssh root@10.5.10.52 service gogs restart
mariabackup --backup --target-dir="$DEST_DIR" --incremental-basedir="${DAY_BACKUP_DIR}${BASE_BACKUP}" --user="$MYSQLUSER" --password="$MYSQLPASS" ssh root@10.5.10.53 service gogs restart
;; exit 0;;
'restore')
if [ "`ps aux | grep --only-match mysqld`" != "" ]; then
read -p "I think mysql-server still running. It's STRONGLY recommended to stop it before restoring any backup to avoid corrupted files. Do you want to continue anyway? [Y/N]" yn
case $yn in
[Yy]* ) break;;
* ) exit;;
esac
fi
REQUEST_BACKUP="${BACKUP_PATH}${2}/${3}" nginx-start)
BASE_BACKUP="${BACKUP_PATH}${2}/`ls ${BACKUP_PATH}${2} | grep --max-count=1 --perl-regexp '^.+_BASE'`" echo -e "${BBlue}NGINX Starting...${Color_Off}"
TMP_BACKUP="${BACKUP_PATH}${2}/.current_backup" service nginx start
ssh root@10.5.10.52 service nginx start
ssh root@10.5.10.53 service nginx start
exit 0;;
if [ ! -d "$REQUEST_BACKUP" ] || [ ! $2 ] || [ ! $3 ]; then nginx-stop)
echo -e "${idsCL[Red]}Backup not found!${idsCL[Default]}" echo -e "${BBlue}NGINX Stopping...${Color_Off}"
echo "Usage: $0 restore 2019-01-05 13-00-10" service nginx stop
exit 1 ssh root@10.5.10.52 service nginx stop
fi ssh root@10.5.10.53 service nginx stop
exit 0;;
if [ -d "$MYSQLDATA" ]; then nginx-restart)
mv "$MYSQLDATA" "`grep --perl-regexp --only-match '^.*(?=/$)' <<< ${MYSQLDATA}`_restore-`date +%Y-%m-%d_%H-%M-%S`" echo -e "${BBlue}NGINX Restarting...${Color_Off}"
mkdir "$MYSQLDATA" service nginx restart
fi ssh root@10.5.10.52 service nginx restart
ssh root@10.5.10.53 service nginx restart
exit 0;;
if [ -d "$TMP_BACKUP" ]; then reload)
rm -rf "$TMP_BACKUP" service nginx reload
fi ssh root@10.5.10.52 service nginx reload
ssh root@10.5.10.53 service nginx reload
exit 0
;;
cp --recursive "$BASE_BACKUP" "$TMP_BACKUP" new)
innobackupex --apply-log --redo-only "$TMP_BACKUP" # "$0" stop
echo -e "${Green}Requesting Certificate for '${BBlue}$2${Green}'...${Color_Off}"
# $DAEMON certonly --standalone -d $2
$DAEMON certonly --webroot -w /var/www/html -d $2
# chown -R root:letsencrypt /etc/letsencrypt
# chmod -R 6775 /etc/letsencrypt
# "$0" start
# redirect_artica-ssl_files
exit 0
;;
if [ REQUEST_BACKUP != BASE_BACKUP ]; then new-mass)
innobackupex --apply-log "$TMP_BACKUP" --incremental-dir="$REQUEST_BACKUP" echo -e "${Green}Requesting Certificate for '${BBlue}$2${Green}'...${Color_Off}"
fi # $DAEMON certonly --standalone -d $2
$DAEMON certonly --webroot -w /var/www/html -d $2
# chown -R root:letsencrypt /etc/letsencrypt
# chmod -R 6775 /etc/letsencrypt
# redirect_artica-ssl_files
exit 0
;;
innobackupex --apply-log "$TMP_BACKUP" renew)
innobackupex --copy-back "$TMP_BACKUP" "$0" stop
chown -R mysql:mysql "$MYSQLDATA" echo -e "${Green}Renewing Certificates...${Color_Off}"
# $DAEMON renew
$DAEMON renew certonly --webroot -w /var/www/html -d $2
chown -R root:letsencrypt /etc/letsencrypt
chmod -R 6775 /etc/letsencrypt
"$0" start
# redirect_artica-ssl_files
exit 0
;;
rm -rf "$TMP_BACKUP" nightlyrenew)
;; rm -f /opt/runcerts/cert-renewal-run-$(hostname)
'list') "$0" stop >> /opt/runcerts/cert-renewal-run-$(hostname)
clear # $DAEMON renew >> /opt/runcerts/cert-renewal-run-$(hostname)
echo "" $DAEMON renew certonly --webroot -w /var/www/html -d $2 >> /opt/runcerts/cert-renewal-run-$(hostname)
echo -e " ${idsCL[LightGreen]}MySQL-BU - M y S Q L B A C K U P S C R I P T S${idsCL[Default]} ${idsCL[DarkGray]}(ver-${VERS})${idsCL[Default]}" chown -R root:letsencrypt /etc/letsencrypt
echo -e "${idsCL[LightGreen]}---------------------------------------------------------------------------${idsCL[Default]}" chmod -R 6775 /etc/letsencrypt
echo "" "$0" start >> /opt/runcerts/cert-renewal-run-$(hostname)
echo -e "${idsCL[LightYellow]}============ Available MySQL Backups ============${idsCL[Default]}" exit 0
for day in $BACKUP_PATH* ; do ;;
tdt=`sed 's/.*\///' <<< $day`
bsz=`du -sh ${day} | awk '{print $1}'`
echo -e "${idsBG[Blue]}${idsCL[White]}-> `date -d"${tdt}" +"%a, %B %d, %Y"` - ${bsz} ${idsCL[Default]}${idsBG[Default]}" redirect-ssl)
redirect_artica-ssl_files
service nginx restart
read -n 1 -t 10 -p "Are you sure you wish to reboot (y/N)?" redirect_choice
case "$redirect_choice" in
[Yy]) if [ "$EUID" -ne 0 ]
then
service artica-webservices restart
fi
exit 0;;
esac
exit 0;;
;;
'gui') MAIN_MENU;;
*)
echo
echo
echo "Usage: $0 {new|new-mass|renew|redirect-ssl|stop|start}"
echo
echo "'new' - Creates a new certificate."
echo "---------------------------------------------------------------------------------------"
echo "examples:"
echo " single-domain = 'runcerts new www.example.com'"
echo " multiple-domains = 'runcerts new www.example.com,dev.example.com,...'"
echo
echo "'new-mass' - Creates a new certificate, but doesnt go through the"
echo " process of stopping and restarting nginx each time"
echo "---------------------------------------------------------------------------------------"
echo "examples (same as 'new'):"
echo " single-domain = 'runcerts new-mass www.example.com'"
echo " multiple-domains = 'runcerts new-mass www.example.com,dev.example.com,...'"
echo
echo "'renew' - Renews all certificates. This command could be run routinly by adding this"
echo " line into crontab: \"0 4 * * 0 /usr/local/bin/runcerts renew\""
echo "---------------------------------------------------------------------------------------"
echo "examples:"
echo " 'runcerts renew'"
echo
echo "'redirect-ssl' - Redirects the configured Artica certificates to use the LetsEncrypt certificates"
echo "---------------------------------------------------------------------------------------"
echo "examples:"
echo " 'runcerts redirect-ssl'"
echo
echo "'stop' - Stops any process that interfere with creating a standalone server"
echo "---------------------------------------------------------------------------------------"
echo "examples:"
echo " 'runcerts stop'"
echo
echo "'start' - Starts any process that had interfered with creating a standalone server"
echo "---------------------------------------------------------------------------------------"
echo "examples:"
echo " 'runcerts start'"
echo
exit 1
;;
for hour in $day/* ; do
thr=`sed 's/.*\///' <<< ${hour//_BASE/}`
bsz=`du -sh ${hour} | awk '{print $1}'`
if [ ${hour: -5} = "_BASE" ]; then
echo -e "${idsCL[LightGreen]}${idsST[Bold]} -> `date -d"${tdt} ${thr//-/:}" +"%I:%M %P"` - FULL BACKUP${idsST[Reset]}${idsCL[LightGreen]} - ${bsz}${idsCL[Default]}"
else
echo -e "${idsCL[Cyan]} -> `date -d"${tdt} ${thr//-/:}" +"%I:%M %P"` - Incremental - ${bsz}${idsCL[Default]}"
fi
done
done
echo -e "${idsCL[Yellow]}=================================================${idsCL[Default]}"
echo ""
;;
'gui')
MAIN_MENU
;; 'delete')
DELETE_MENU
;;
*)
echo "Usage: $0 { gui | backup | backup-base | backup-incremental | restore | list }"
;;
esac esac
exit 0 exit 0