How to restore our internal server from aws (s3bucket)?
Prerequisites
Before starting, ensure you have:
1. Server root login credentials.
Step 1:
Log into server
ssh username@ip
Step 2:
Install AWS CLI and configure
apt-get update apt-get install awscli aws configure
Note: Provide access & secret key while configuring
Step 3:
Copy the backup files from S3 to server
aws s3 cp s3://cablemanagement-63141233102/apachebackup_1701220000.tar . aws s3 cp s3://cablemanagement-63141233102/sitebackup_1701220000.tar . aws s3 cp s3://cablemanagement-63141233102/sitebackup1_1701220000.tar . aws s3 cp s3://cablemanagement-63141233102/db_backups/db_backups-2022-01-17-0000.tar.gz .
Step 4:
Install apache2 and MySQL
apt-get update apt-get install apache2 apt update apt install mysql-server
Note: If this restoration is done on a new server we need to install apache2, mysql, mongodb. It's based on the developer requirement.If it is old server we need to check whether we have or not
Step 5:
Untar the backup file and copy the home directory
tar -xvf sitebackup_1701220000.tar cp -pr home /
Step 6:
First we will set up the backend code. Go into the fitness_be and create a .env file. Include the db credentials like below
cd taxary vi .env
Copy and paste the below.
PORT = 4006
OTP_KEY = 5dd572c3-87c0-11ea-9fa5-0200cd936042
DBLINK = mongodb://127.0.0.1:27017/fitness_be
JWT_SECRET=abcfghistuvwxyz123456789
JWT_TIMEOUT_DURATION="2d"
AUTHSOURCE = admin
USER = admin
PASS = ******
Note:- Modify the username and password as per your wish. |}
Step 7:-
First we have to add curl to the system
apt-get install curl curl -fsSL https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add - echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
Step 8:
Install mongodb
apt update apt install mongodb-org sudo systemctl start mongod.service sudo systemctl status mongod sudo systemctl enable mongod
Step 9:
After installing mongodb. Follow the below commands.
mongo( you will be entering in to mongo)
use admin;
Remember, If you don't use the admin database the below creation wont work. You will end up with errors.
db.createUser( {user: “admin",pwd: “password",roles: [ { role: "userAdminAnyDatabase", db:”admin" },{ role: "dbAdminAnyDatabase", db: “admin" },{ role:"readWriteAnyDatabase", db: “admin" },{ role: 'root', db: 'admin' } ]}) If you forget to give root access to the user, you can execute like belo
use admin;
db.grantRolesToUser('admin', [{ role: 'root', db: 'admin' }])
To check the privileges of the user
db.getUser("admin")
To delete or drop the user
db.dropUser("admin", {w: "majority", wtimeout: 5000})
Step 10:
Install node js (required node version) and pm2. You can ask the developer for the version.
Example:-
https://computingforgeeks.com/how-to-install-nodejs-on-ubuntu-debian-linux-mint/
npm install -g pm2 sudo apt update sudo apt -y upgrade sudo apt update sudo apt -y install curl dirmngr apt-transport-https lsb-release ca-certificates curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - sudo apt -y install nodejs sudo apt -y install gcc g++ make node --version npm --version mkdir ~/projects cd ~/projects vi hello-world.js node hello-world.js
Step 11:
Add user nagios and install daemon & nrpe (Nagios Remote Plugin Executor).
Note: These may vary according to the requirement of the developer
sudo useradd nagios sudo apt update sudo apt install autoconf gcc libmcrypt-dev make libssl-dev wget dc build-essential gettext cd ~ curl -L -O https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz tar -zxf nagios-plugins-2.2.1.tar.gz cd nagios-plugins-2.2.1 ./configure make sudo make install cd ~ curl -L -O https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-3.2.1/nrpe-3.2.1.tar.gz tar zxf nrpe-3.2.1.tar.gz cd nrpe-3.2.1 ./configure make nrpe sudo make install-daemon sudo make install-config sudo make install-init df -h / vi /usr/local/nagios/etc/nrpe.cfg cd /home mv check_mem /usr/local/nagios/libexec systemctl restart nrpe vi /usr/local/nagios/etc/nrpe.cfg systemctl restart nrpe mv check_mem /usr/local/nagios/libexec cd /usr/local/nagios/libexec systemctl restart nrpe /usr/local/nagios/libexec/check_mem vi /usr/local/nagios/etc/nrpe.cfg