Update nodemgmt-scripts.sh
This commit is contained in:
@@ -64,134 +64,184 @@ MAIN_MENU() {
|
||||
done
|
||||
}
|
||||
|
||||
case $1 in
|
||||
'backup')
|
||||
if [ "$BASE_BACKUP" = "" ]; then
|
||||
$0 backup-base
|
||||
else
|
||||
$0 backup-incremental
|
||||
fi
|
||||
|
||||
allfiles=`ls -1 ${BACKUP_PATH}`
|
||||
files=(`ls -1 ${BACKUP_PATH} | tail -${BACKUPSTOKEEP}`)
|
||||
for i in $allfiles; do
|
||||
keep=0;
|
||||
for a in ${files[@]}; do
|
||||
if [ $i == $a ]; then
|
||||
keep=1;
|
||||
fi;
|
||||
done;
|
||||
if [ $keep == 0 ]; then
|
||||
rm -rf ${BACKUP_PATH}$i;
|
||||
fi;
|
||||
done
|
||||
;;
|
||||
'backup-base')
|
||||
DEST_DIR="${DAY_BACKUP_DIR}`date +%H-%M-%S`_BASE"
|
||||
|
||||
if [ "$BASE_BACKUP" != "" ]; then
|
||||
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
|
||||
mkdir -p "$DAY_BACKUP_DIR"
|
||||
fi
|
||||
|
||||
# innobackupex --defaults-file="$MYSQLCFG" --user="$MYSQLUSER" --password="$MYSQLPASS" --no-timestamp "$DEST_DIR"
|
||||
mariabackup --backup --target-dir="$DEST_DIR" --user="$MYSQLUSER" --password="$MYSQLPASS"
|
||||
;;
|
||||
'backup-incremental')
|
||||
DEST_DIR="${DAY_BACKUP_DIR}`date +%H-%M-%S`"
|
||||
|
||||
if [ "$BASE_BACKUP" = "" ]; then
|
||||
echo -e "${idsCL[Green]}Daily base backup not found. Running base backup...${idsCL[Default]}"
|
||||
$0 backup-base
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#innobackupex --defaults-file="$MYSQLCFG" --user="$MYSQLUSER" --password="$MYSQLPASS" \
|
||||
#--incremental-basedir="${DAY_BACKUP_DIR}${BASE_BACKUP}" \
|
||||
#--incremental "$DEST_DIR" \
|
||||
#--no-timestamp
|
||||
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
|
||||
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}"
|
||||
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')
|
||||
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 }"
|
||||
;;
|
||||
case "$1" in
|
||||
|
||||
start)
|
||||
sleep 15
|
||||
echo -e "${BBlue}HAProxy Starting...${Color_Off}"
|
||||
service haproxy start
|
||||
ssh root@10.5.10.52 service haproxy start
|
||||
ssh root@10.5.10.53 service haproxy start
|
||||
echo -e "${BBlue}NGINX Reload...${Color_Off}"
|
||||
service nginx reload
|
||||
ssh root@10.5.10.52 service nginx reload
|
||||
ssh root@10.5.10.53 service nginx reload
|
||||
|
||||
exit 0
|
||||
;;
|
||||
|
||||
stop)
|
||||
echo -e "${BBlue}HAProxy Stopping...${Color_Off}"
|
||||
service haproxy stop
|
||||
ssh root@10.5.10.52 service haproxy stop
|
||||
ssh root@10.5.10.53 service haproxy stop
|
||||
exit 0;;
|
||||
|
||||
gogs-start)
|
||||
echo -e "${BBlue}Gogs Starting...${Color_Off}"
|
||||
service gogs start
|
||||
ssh root@10.5.10.52 service gogs start
|
||||
ssh root@10.5.10.53 service gogs start
|
||||
exit 0;;
|
||||
|
||||
gogs-stop)
|
||||
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
|
||||
;;
|
||||
|
||||
new)
|
||||
# "$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
|
||||
;;
|
||||
|
||||
new-mass)
|
||||
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
|
||||
# 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
|
||||
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
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user