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; exit 0
done
;; ;;
'backup-base')
DEST_DIR="${DAY_BACKUP_DIR}`date +%H-%M-%S`_BASE"
if [ "$BASE_BACKUP" != "" ]; then stop)
echo -e "${idsCL[Green]}Daily base backup already done. Running incremental backup...${idsCL[Default]}" echo -e "${BBlue}HAProxy Stopping...${Color_Off}"
sleep 3 service haproxy stop
$0 backup-incremental ssh root@10.5.10.52 service haproxy stop
exit 1 ssh root@10.5.10.53 service haproxy stop
fi exit 0;;
if [ ! -d "$DAY_BACKUP_DIR" ]; then gogs-start)
mkdir -p "$DAY_BACKUP_DIR" echo -e "${BBlue}Gogs Starting...${Color_Off}"
fi service gogs start
ssh root@10.5.10.52 service gogs start
ssh root@10.5.10.53 service gogs start
exit 0;;
# innobackupex --defaults-file="$MYSQLCFG" --user="$MYSQLUSER" --password="$MYSQLPASS" --no-timestamp "$DEST_DIR" gogs-stop)
mariabackup --backup --target-dir="$DEST_DIR" --user="$MYSQLUSER" --password="$MYSQLPASS" echo -e "${BBlue}Gogs Stopping...${Color_Off}"
service gogs stop
ssh root@10.5.10.52 service gogs stop
ssh root@10.5.10.53 service gogs stop
exit 0;;
gogs-restart)
echo -e "${BBlue}Gogs Restarting...${Color_Off}"
service gogs restart
ssh root@10.5.10.52 service gogs restart
ssh root@10.5.10.53 service gogs restart
exit 0;;
nginx-start)
echo -e "${BBlue}NGINX Starting...${Color_Off}"
service nginx start
ssh root@10.5.10.52 service nginx start
ssh root@10.5.10.53 service nginx start
exit 0;;
nginx-stop)
echo -e "${BBlue}NGINX Stopping...${Color_Off}"
service nginx stop
ssh root@10.5.10.52 service nginx stop
ssh root@10.5.10.53 service nginx stop
exit 0;;
nginx-restart)
echo -e "${BBlue}NGINX Restarting...${Color_Off}"
service nginx restart
ssh root@10.5.10.52 service nginx restart
ssh root@10.5.10.53 service nginx restart
exit 0;;
reload)
service nginx reload
ssh root@10.5.10.52 service nginx reload
ssh root@10.5.10.53 service nginx reload
exit 0
;; ;;
'backup-incremental')
DEST_DIR="${DAY_BACKUP_DIR}`date +%H-%M-%S`"
if [ "$BASE_BACKUP" = "" ]; then new)
echo -e "${idsCL[Green]}Daily base backup not found. Running base backup...${idsCL[Default]}" # "$0" stop
$0 backup-base echo -e "${Green}Requesting Certificate for '${BBlue}$2${Green}'...${Color_Off}"
exit 1 # $DAEMON certonly --standalone -d $2
fi $DAEMON certonly --webroot -w /var/www/html -d $2
# chown -R root:letsencrypt /etc/letsencrypt
#innobackupex --defaults-file="$MYSQLCFG" --user="$MYSQLUSER" --password="$MYSQLPASS" \ # chmod -R 6775 /etc/letsencrypt
#--incremental-basedir="${DAY_BACKUP_DIR}${BASE_BACKUP}" \ # "$0" start
#--incremental "$DEST_DIR" \ # redirect_artica-ssl_files
#--no-timestamp exit 0
mariabackup --backup --target-dir="$DEST_DIR" --incremental-basedir="${DAY_BACKUP_DIR}${BASE_BACKUP}" --user="$MYSQLUSER" --password="$MYSQLPASS"
;; ;;
'restore')
if [ "`ps aux | grep --only-match mysqld`" != "" ]; then new-mass)
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 echo -e "${Green}Requesting Certificate for '${BBlue}$2${Green}'...${Color_Off}"
case $yn in # $DAEMON certonly --standalone -d $2
[Yy]* ) break;; $DAEMON certonly --webroot -w /var/www/html -d $2
* ) exit;; # chown -R root:letsencrypt /etc/letsencrypt
# chmod -R 6775 /etc/letsencrypt
# redirect_artica-ssl_files
exit 0
;;
renew)
"$0" stop
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
;;
nightlyrenew)
rm -f /opt/runcerts/cert-renewal-run-$(hostname)
"$0" stop >> /opt/runcerts/cert-renewal-run-$(hostname)
# $DAEMON renew >> /opt/runcerts/cert-renewal-run-$(hostname)
$DAEMON renew certonly --webroot -w /var/www/html -d $2 >> /opt/runcerts/cert-renewal-run-$(hostname)
chown -R root:letsencrypt /etc/letsencrypt
chmod -R 6775 /etc/letsencrypt
"$0" start >> /opt/runcerts/cert-renewal-run-$(hostname)
exit 0
;;
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 esac
fi exit 0;;
REQUEST_BACKUP="${BACKUP_PATH}${2}/${3}"
BASE_BACKUP="${BACKUP_PATH}${2}/`ls ${BACKUP_PATH}${2} | grep --max-count=1 --perl-regexp '^.+_BASE'`"
TMP_BACKUP="${BACKUP_PATH}${2}/.current_backup"
if [ ! -d "$REQUEST_BACKUP" ] || [ ! $2 ] || [ ! $3 ]; then
echo -e "${idsCL[Red]}Backup not found!${idsCL[Default]}"
echo "Usage: $0 restore 2019-01-05 13-00-10"
exit 1
fi
if [ -d "$MYSQLDATA" ]; then
mv "$MYSQLDATA" "`grep --perl-regexp --only-match '^.*(?=/$)' <<< ${MYSQLDATA}`_restore-`date +%Y-%m-%d_%H-%M-%S`"
mkdir "$MYSQLDATA"
fi
if [ -d "$TMP_BACKUP" ]; then
rm -rf "$TMP_BACKUP"
fi
cp --recursive "$BASE_BACKUP" "$TMP_BACKUP"
innobackupex --apply-log --redo-only "$TMP_BACKUP"
if [ REQUEST_BACKUP != BASE_BACKUP ]; then
innobackupex --apply-log "$TMP_BACKUP" --incremental-dir="$REQUEST_BACKUP"
fi
innobackupex --apply-log "$TMP_BACKUP"
innobackupex --copy-back "$TMP_BACKUP"
chown -R mysql:mysql "$MYSQLDATA"
rm -rf "$TMP_BACKUP"
;; ;;
'list') 'gui') MAIN_MENU;;
clear
echo ""
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]}"
echo -e "${idsCL[LightGreen]}---------------------------------------------------------------------------${idsCL[Default]}"
echo ""
echo -e "${idsCL[LightYellow]}============ Available MySQL Backups ============${idsCL[Default]}"
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]}"
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 }" 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
;; ;;
esac esac
exit 0 exit 0