Wednesday, May 12, 2021

MongoDB Backups scripts and reference urls

How To Set Up Scheduled MongoDB Backups to DigitalOcean Spaces

Reference URLs

URL: : https://www.digitalocean.com/community/tutorials/how-to-set-up-scheduled-logical-mongodb-backups-to-digitalocean-spaces


URL: https://tecadmin.net/shell-script-backup-mongodb-database/

URL: https://sqlbak.com/blog/how-to-automate-mongodb-database-backups-in-linux

URL: https://tecadmin.net/shell-script-backup-mongodb-database/

URL: https://gist.github.com/sheharyarn/0f04c1ba18462cddaaf5

URL: https://simplebackups.io/blog/the-ultimate-mongodb-database-backup-script/


#!/bin/bash

######################################################################

##

##   MongoDB Database Backup Script 

##   Written By: Tushar Jadhav

##

######################################################################

export PATH=/bin:/usr/bin:/usr/local/bin

TODAY=`date +"%d%b%Y"`

######################################################################

DB_BACKUP_PATH='/backup/mongo'

MONGO_HOST='localhost'

MONGO_PORT='27017'

# If mongodb is protected with username password.

# Set AUTH_ENABLED to 1 

# and add MONGO_USER and MONGO_PASSWD values correctly

AUTH_ENABLED=0

MONGO_USER=''

MONGO_PASSWD=''


# Set DATABASE_NAMES to "ALL" to backup all databases.

# or specify databases names seprated with space to backup 

# specific databases only.


DATABASE_NAMES='ALL'

#DATABASE_NAMES='mydb db2 newdb'


## Number of days to keep local backup copy

BACKUP_RETAIN_DAYS=30   

######################################################################

mkdir -p ${DB_BACKUP_PATH}/${TODAY}

AUTH_PARAM=""

if [ ${AUTH_ENABLED} -eq 1 ]; then

 AUTH_PARAM=" --username ${MONGO_USER} --password ${MONGO_PASSWD} "

fi

if [ ${DATABASE_NAMES} = "ALL" ]; then

 echo "You have choose to backup all databases"

 mongodump --host ${MONGO_HOST} --port ${MONGO_PORT} ${AUTH_PARAM} --out ${DB_BACKUP_PATH}/${TODAY}/

else

 echo "Running backup for selected databases"

 for DB_NAME in ${DATABASE_NAMES}

 do

 mongodump --host ${MONGO_HOST} --port ${MONGO_PORT} --db ${DB_NAME} ${AUTH_PARAM} --out ${DB_BACKUP_PATH}/${TODAY}/

 done

fi

######## Remove backups older than {BACKUP_RETAIN_DAYS} days  ########

DBDELDATE=`date +"%d%b%Y" --date="${BACKUP_RETAIN_DAYS} days ago"`

if [ ! -z ${DB_BACKUP_PATH} ]; then

      cd ${DB_BACKUP_PATH}

      if [ ! -z ${DBDELDATE} ] && [ -d ${DBDELDATE} ]; then

            rm -rf ${DBDELDATE}

      fi

fi

######################### End of script ##############################

Thursday, April 1, 2021

Setup Jenkins and Tomcat server

Login to aws instance or VM and add user

useradd devops

passwd devops

Edit this file /etc/ssh/sshd_config and enable PasswordAuthentication

PasswordAuthentication yes

Restart SSHD Service

systemctl restart sshd
------------------------------------------------------------------------------------------------------------
Install java 1.8 version

yum install java-1.8* -y
















Set java path : /root/.bash_profile
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-0.amzn2.x86_64
echo $JAVA_HOME
source /root/.bash_profile
------------------------------------------------------------------------------------------------------------
Download Jenkins repo

Ref : https://docs.aws.amazon.com/aws-technical-content/latest/jenkins-on-aws/installation.html
 
wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins.io/redhat/jenkins.repo

rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key
yum install jenkins -y 
service jenkins start   or  systemctl start jenkin
Open 8080 port 
http://localhost:8080/
Password location :  /var/lib/jenkins/secrets/initialAdminPassword
 
Secure Jenkins server

1. Change admin password

2. Remove the secret password file ( /var/lib/jenkins/secrets/initialAdminPassword )

3. Configure Global Security - Enable Security

4. Configure Global Security - Enable Project-based Matrix Authorization Strategy and role base Authorization

5. Configure Global Security - Disable SSH Server

------------------------------------------------------------------------------------------------------------
Install Maven & Git  installation and configuration 
 
Ref : https://maven.apache.org/download.cgi
 
Create maven folder in opt
Install wget and downloads below maven packages

wget http://mirrors.estointernet.in/apache/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz

###  /root/.bash_profile  ######
 
# User specific environment and startup programs
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-0.amzn2.x86_64
 
M2_HOME=/opt/maven/apache-maven-3.6.0
M2=$M2_HOME/bin
PATH=$PATH:$JAVA_HOME:$HOME/.local/bin:$HOME/bin
------------------------------------------------------------------------------------------------------------
Select maven_invoker and github
 
And path in Global Tool Configuration





























------------------------------------------------------------------------------------------------------------

Install Publish Over SSH  plugging for Ansible integration and send build artifacts over SSH



Download below tomcat package

wget http://mirrors.estointernet.in/apache/tomcat/tomcat-8/v8.5.38/bin/apache-tomcat-8.5.38.tar.gz
 
Ref : https://tomcat.apache.org/download-80.cgi
 
cd /opt/apache-tomcat-8.5.38/bin/      -----  After extract you  get this folder
 
chmod +x startup.sh  shutdown.sh     ----- Give execute permission to  startup.sh and  shutdown.sh 
 
 
Create soft link 
ln -s /opt/apache-tomcat-8.5.38/bin/startup.sh /usr/bin/tomcatup
ln -s /opt/apache-tomcat-8.5.38/bin/shutdown.sh /usr/bin/tomcatdown
 
Tomcatup   -------------------------   start tomcat
 
 ps -ef |grep tomcat   -----------------------  check tomcat is running or not
 
/opt/apache-tomcat-8.5.38/conf   ----------   go to conf directory and edit server.xml 
 

Edit server.xml and change tomcat port
 


 




Change 8080 to 8090
 
Restart tomcat
 
tomcatdown   --------------  stop the service
 
tomcatup      ---------------   start the service



















URL : http://ServerIP:8090/manager/










Solution for above issue: 
 find / -name context.xml
/opt/apache-tomcat-8.5.38/conf/context.xml
/opt/apache-tomcat-8.5.38/webapps/host-manager/META-INF/context.xml
/opt/apache-tomcat-8.5.38/webapps/manager/META-INF/context.xml
 
Edit both the files and uncomment below line






Restart tomcat
 
tomcatdown   --------------  stop the service
 
tomcatup      ---------------   start the service


How to set user and password  add following roles
 
Edit this file /opt/apache-tomcat-8.5.38/conf/tomcat-users.xml
 
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="admin" password="admin" roles="manager-gui, manager-script, manager-jmx, manager-status"/>
<user username="deployer" password="deployer_user" roles="manager-script"/>
<user username="tomcat" password="s321cret" roles="manager-gui"/><feff>

---------------------------------------------------  END  -----------------------------------------------------