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 start)
$0 backup-base sleep 15
else echo -e "${BBlue}HAProxy Starting...${Color_Off}"
$0 backup-incremental service haproxy start
fi ssh root@10.5.10.52 service haproxy start
ssh root@10.5.10.53 service haproxy start
allfiles=`ls -1 ${BACKUP_PATH}` echo -e "${BBlue}NGINX Reload...${Color_Off}"
files=(`ls -1 ${BACKUP_PATH} | tail -${BACKUPSTOKEEP}`) service nginx reload
for i in $allfiles; do ssh root@10.5.10.52 service nginx reload
keep=0; ssh root@10.5.10.53 service nginx reload
for a in ${files[@]}; do
if [ $i == $a ]; then exit 0
keep=1; ;;
fi;
done; stop)
if [ $keep == 0 ]; then echo -e "${BBlue}HAProxy Stopping...${Color_Off}"
rm -rf ${BACKUP_PATH}$i; service haproxy stop
fi; ssh root@10.5.10.52 service haproxy stop
done ssh root@10.5.10.53 service haproxy stop
;; exit 0;;
'backup-base')
DEST_DIR="${DAY_BACKUP_DIR}`date +%H-%M-%S`_BASE" gogs-start)
echo -e "${BBlue}Gogs Starting...${Color_Off}"
if [ "$BASE_BACKUP" != "" ]; then service gogs start
echo -e "${idsCL[Green]}Daily base backup already done. Running incremental backup...${idsCL[Default]}" ssh root@10.5.10.52 service gogs start
sleep 3 ssh root@10.5.10.53 service gogs start
$0 backup-incremental exit 0;;
exit 1
fi gogs-stop)
echo -e "${BBlue}Gogs Stopping...${Color_Off}"
if [ ! -d "$DAY_BACKUP_DIR" ]; then service gogs stop
mkdir -p "$DAY_BACKUP_DIR" 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" --no-timestamp "$DEST_DIR"
mariabackup --backup --target-dir="$DEST_DIR" --user="$MYSQLUSER" --password="$MYSQLPASS" gogs-restart)
;; echo -e "${BBlue}Gogs Restarting...${Color_Off}"
'backup-incremental') service gogs restart
DEST_DIR="${DAY_BACKUP_DIR}`date +%H-%M-%S`" ssh root@10.5.10.52 service gogs restart
ssh root@10.5.10.53 service gogs restart
if [ "$BASE_BACKUP" = "" ]; then exit 0;;
echo -e "${idsCL[Green]}Daily base backup not found. Running base backup...${idsCL[Default]}"
$0 backup-base nginx-start)
exit 1 echo -e "${BBlue}NGINX Starting...${Color_Off}"
fi service nginx start
ssh root@10.5.10.52 service nginx start
#innobackupex --defaults-file="$MYSQLCFG" --user="$MYSQLUSER" --password="$MYSQLPASS" \ ssh root@10.5.10.53 service nginx start
#--incremental-basedir="${DAY_BACKUP_DIR}${BASE_BACKUP}" \ exit 0;;
#--incremental "$DEST_DIR" \
#--no-timestamp nginx-stop)
mariabackup --backup --target-dir="$DEST_DIR" --incremental-basedir="${DAY_BACKUP_DIR}${BASE_BACKUP}" --user="$MYSQLUSER" --password="$MYSQLPASS" echo -e "${BBlue}NGINX Stopping...${Color_Off}"
;; service nginx stop
'restore') ssh root@10.5.10.52 service nginx stop
if [ "`ps aux | grep --only-match mysqld`" != "" ]; then ssh root@10.5.10.53 service nginx stop
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 exit 0;;
case $yn in
[Yy]* ) break;; nginx-restart)
* ) exit;; echo -e "${BBlue}NGINX Restarting...${Color_Off}"
esac service nginx restart
fi ssh root@10.5.10.52 service nginx restart
ssh root@10.5.10.53 service nginx restart
REQUEST_BACKUP="${BACKUP_PATH}${2}/${3}" exit 0;;
BASE_BACKUP="${BACKUP_PATH}${2}/`ls ${BACKUP_PATH}${2} | grep --max-count=1 --perl-regexp '^.+_BASE'`"
TMP_BACKUP="${BACKUP_PATH}${2}/.current_backup" reload)
service nginx reload
if [ ! -d "$REQUEST_BACKUP" ] || [ ! $2 ] || [ ! $3 ]; then ssh root@10.5.10.52 service nginx reload
echo -e "${idsCL[Red]}Backup not found!${idsCL[Default]}" ssh root@10.5.10.53 service nginx reload
echo "Usage: $0 restore 2019-01-05 13-00-10" exit 0
exit 1 ;;
fi
new)
if [ -d "$MYSQLDATA" ]; then # "$0" stop
mv "$MYSQLDATA" "`grep --perl-regexp --only-match '^.*(?=/$)' <<< ${MYSQLDATA}`_restore-`date +%Y-%m-%d_%H-%M-%S`" echo -e "${Green}Requesting Certificate for '${BBlue}$2${Green}'...${Color_Off}"
mkdir "$MYSQLDATA" # $DAEMON certonly --standalone -d $2
fi $DAEMON certonly --webroot -w /var/www/html -d $2
# chown -R root:letsencrypt /etc/letsencrypt
if [ -d "$TMP_BACKUP" ]; then # chmod -R 6775 /etc/letsencrypt
rm -rf "$TMP_BACKUP" # "$0" start
fi # redirect_artica-ssl_files
exit 0
cp --recursive "$BASE_BACKUP" "$TMP_BACKUP" ;;
innobackupex --apply-log --redo-only "$TMP_BACKUP"
new-mass)
if [ REQUEST_BACKUP != BASE_BACKUP ]; then echo -e "${Green}Requesting Certificate for '${BBlue}$2${Green}'...${Color_Off}"
innobackupex --apply-log "$TMP_BACKUP" --incremental-dir="$REQUEST_BACKUP" # $DAEMON certonly --standalone -d $2
fi $DAEMON certonly --webroot -w /var/www/html -d $2
# chown -R root:letsencrypt /etc/letsencrypt
innobackupex --apply-log "$TMP_BACKUP" # chmod -R 6775 /etc/letsencrypt
innobackupex --copy-back "$TMP_BACKUP" # redirect_artica-ssl_files
chown -R mysql:mysql "$MYSQLDATA" exit 0
;;
rm -rf "$TMP_BACKUP"
;; renew)
'list') "$0" stop
clear echo -e "${Green}Renewing Certificates...${Color_Off}"
echo "" # $DAEMON renew
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]}" $DAEMON renew certonly --webroot -w /var/www/html -d $2
echo -e "${idsCL[LightGreen]}---------------------------------------------------------------------------${idsCL[Default]}" chown -R root:letsencrypt /etc/letsencrypt
echo "" chmod -R 6775 /etc/letsencrypt
echo -e "${idsCL[LightYellow]}============ Available MySQL Backups ============${idsCL[Default]}" "$0" start
for day in $BACKUP_PATH* ; do # redirect_artica-ssl_files
tdt=`sed 's/.*\///' <<< $day` exit 0
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]}"
nightlyrenew)
for hour in $day/* ; do rm -f /opt/runcerts/cert-renewal-run-$(hostname)
thr=`sed 's/.*\///' <<< ${hour//_BASE/}` "$0" stop >> /opt/runcerts/cert-renewal-run-$(hostname)
bsz=`du -sh ${hour} | awk '{print $1}'` # $DAEMON renew >> /opt/runcerts/cert-renewal-run-$(hostname)
if [ ${hour: -5} = "_BASE" ]; then $DAEMON renew certonly --webroot -w /var/www/html -d $2 >> /opt/runcerts/cert-renewal-run-$(hostname)
echo -e "${idsCL[LightGreen]}${idsST[Bold]} -> `date -d"${tdt} ${thr//-/:}" +"%I:%M %P"` - FULL BACKUP${idsST[Reset]}${idsCL[LightGreen]} - ${bsz}${idsCL[Default]}" chown -R root:letsencrypt /etc/letsencrypt
else chmod -R 6775 /etc/letsencrypt
echo -e "${idsCL[Cyan]} -> `date -d"${tdt} ${thr//-/:}" +"%I:%M %P"` - Incremental - ${bsz}${idsCL[Default]}" "$0" start >> /opt/runcerts/cert-renewal-run-$(hostname)
fi exit 0
done ;;
done
echo -e "${idsCL[Yellow]}=================================================${idsCL[Default]}"
echo "" redirect-ssl)
;; redirect_artica-ssl_files
'gui') service nginx restart
MAIN_MENU
;; 'delete') read -n 1 -t 10 -p "Are you sure you wish to reboot (y/N)?" redirect_choice
DELETE_MENU case "$redirect_choice" in
;; [Yy]) if [ "$EUID" -ne 0 ]
*) then
echo "Usage: $0 { gui | backup | backup-base | backup-incremental | restore | list }" 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
;;
esac esac
exit 0 exit 0