#!/bin/bash
# This file is used in db_backup_daily.sh, backup_functions.sh
LOCAL_HOST="localhost"
DEBUG=4;
INFO=3;
WARNING=2
ERROR=1;
LOGGING_LEVEL=$INFO;

############## Email Notification Setting ##############
# Specify the email smtp key etc at nano ~/.msmtprc 
#DEV_TO_EMAIL_RECIPIENTS="sagar.chincholkar@snapkirana.co.in,vibhav@msikkay.in"
#DEV_CC_EMAIL_RECIPIENTS="Bharat.limaye@gmail.com,vibhav@msikkay.in"
#
#PROD_TO_EMAIL_RECIPIENTS="sagar.chincholkar@snapkirana.co.in,"
#PROD_CC_EMAIL_RECIPIENTS="Bharat.limaye@gmail.com"
DEV_TO_EMAIL_RECIPIENTS="support@hostingduty.email,ninad@hostingduty.com"
DEV_CC_EMAIL_RECIPIENTS="sagar.chincholkar@snapkirana.co.in,mahesh.deshmukh@arraypointer.com,vibhav@msikkay.in"

PROD_TO_EMAIL_RECIPIENTS="support@hostingduty.email,ninad@hostingduty.com,"
PROD_CC_EMAIL_RECIPIENTS="sagar.chincholkar@snapkirana.co.in,mahesh.deshmukh@arraypointer.com,Bharat.limaye@gmail.com,vibhav@msikkay.in"

EMAIL_FROM="support@hostingduty.email"


############## type of backup to be executed on server ############## 
# if TAKE_FILE_SYSTEM_BACKUP is set to true then then fill ##backup files/Folder list## section in this conf file
TAKE_FILE_SYSTEM_BACKUP=$TRUE ##Valid Values $TRUE/ $FALSE

# if TAKE_DB_BACKUP is set to true then fill ##DB host, Schema detials## section in this conf file
TAKE_DB_BACKUP=$TRUE ##Valid Values $TRUE/ $FALSE

# Switch on and off sending email 
SEND_EMAIL_TO_GROUP=$TRUE

############################################################# File System host details #############################################################
############################# for SSH setup #######################################
############# NOTE to create ubuntu user on all the remote server use##############
############# now login to remote server and execute folloing commands#############
############# sudo adduser ubuntu #################################################
############# give password as 'M@nD1rW@h!B@N3Ga'##################################
############# sudo usermod -aG sudo ubuntu ########################################
############# Open remote srvr firewall for DevApp srvr on 22 port ################
############# ufw allow from 138.201.62.181 to any port 22 ########################
############# on remote server register devApp srvr ssh key #######################
############# ssh-copy-id ubuntu@<remote_server_IP> ###############################
############# if ssh key is not alredy generated create ###########################
############# ssh-keygen -t ed25519################################################
############# keep the key file name default i.e. ~/.ssh/id_ed25519 ###############
############# don't give passphrase else backup automation would fail##############
############# to check if the user is setup properly use ##########################
############# ssh ubuntu@<remote_server_IP> #######################################
############################# for SSH setup #######################################

# SRVR_FUNC_NAME,REMOTE_USER,ARRAY_NAME,SRVR_DOMAIN
# List developement servers detials here
OS_PASS='M@nD1rW@h!B@N3Ga'
OS_USER='ubuntu'
DEV_FILES_SRVR_LIST=(
	"APP-DB,$OS_USER,$OS_PASS,DEV_APP_ARCHIEVE_ARRAY_NAMES,$LOCAL_HOST"
#	"MYSQL,$OS_USER,$OS_PASS,DEV_DB_ARCHIEVE_ARRAY_NAMES,$LOCAL_HOST"
	"ZABBIX,$OS_USER,$OS_PASS,PROD_ZABBIX_ARCHIEVE_ARRAY_NAMES,65.109.142.251"
)


#List Production servers detials here
PROD_FILES_SRVR_LIST=(
	"APP-DB,$OS_USER,$OS_PASS,PROD_APP_ARCHIEVE_ARRAY_NAMES,138.201.83.238"
#	"MYSQL,$OS_USER,$OS_PASS,PROD_DB_ARCHIEVE_ARRAY_NAMES,138.201.83.238"
)

############################# archieve and exculed files/folder standard array #############################
############################# typically do not modify it if not a Server Admin #############################
# Define the ARCHIEVE_ARRAY_NAMES associative array
DEV_APP_ARCHIEVE_ARRAY_NAMES=(
	APACHE_BACKEDUP
	APACHE_BACKEDUP_EXCLUDE
	MYSQL_BACKUP
	PROJECT_BACKUP
	PROJECT_BACKUP_EXCLUDE
	ZABBIX_CLIENT_BACKUP
	GENEARL_INCLUDE
	GENEARL_EXCLUDES
	BACKUP_SERVER
)

DEV_DB_ARCHIEVE_ARRAY_NAMES=(
	MYSQL_BACKUP
	ZABBIX_CLIENT_BACKUP
	GENEARL_INCLUDE
	GENEARL_EXCLUDES
)

PROD_APP_ARCHIEVE_ARRAY_NAMES=(
	APACHE_BACKEDUP
	APACHE_BACKEDUP_EXCLUDE
	MYSQL_BACKUP
	PROJECT_BACKUP
	PROJECT_BACKUP_EXCLUDE
	ZABBIX_CLIENT_BACKUP
	GENEARL_INCLUDE
	GENEARL_EXCLUDES
)

PROD_DB_ARCHIEVE_ARRAY_NAMES=(
	MYSQL_BACKUP
	ZABBIX_CLIENT_BACKUP
	GENEARL_INCLUDE
	GENEARL_EXCLUDES
)

PROD_ZABBIX_ARCHIEVE_ARRAY_NAMES=(
	ZABBIX_CLIENT_BACKUP
	ZABBIX_SERVER_BACKUP
	GENEARL_EXCLUDES
)

MYSQL_BACKUP=(
	"/etc/mysql/mysql.conf.d/"
	"/etc/mysql/conf.d/"
)

APACHE_BACKEDUP=(
#	"/etc/apache2/apache2.conf"
#	"/etc/apache2/conf-available/"
#	"/etc/apache2/conf-enabled/"
#	"/etc/apache2/mods-available/"
#	"/etc/apache2/mods-enabled/"
	"/etc/apache2/sites-available/" 
#	"/etc/apache2/sites-enabled/" 

	"/etc/php/7.4/cli/php.ini"
	"/etc/php/7.4/fpm/php.ini"
)
APACHE_BACKEDUP_EXCLUDE=(
	"--exclude=/etc/apache2/sites-available/000-default.conf" 
	"--exclude=/etc/apache2/sites-available/default-ssl.conf" 
	"--exclude=/etc/apache2/sites-available/*-le-ssl.conf" 
)

PROJECT_BACKUP=(
	"/BBC_images/" 
	"/var/www/html/" 
)
PROJECT_BACKUP_EXCLUDE=(
#	"--exclude=/var/www/html/bbc/b2bservices/sf_services_*/" 
	"--exclude=/var/www/html/bbc/laravelapp/bootstrap/cache/config.php" 
	"--exclude=/var/www/html/bbc_jwt/laravelapp/bootstrap/cache/config.php" 
	"--exclude=/var/www/html/ecomm/bootstrap/cache/config.php" 
	"--exclude=/var/www/html/pos/bootstrap/cache/config.php" 
)

ZABBIX_CLIENT_BACKUP=(
	"/etc/zabbix/zabbix_agentd.conf"
)

ZABBIX_SERVER_BACKUP=(
	"/etc/zabbix/nginx.conf"
	"/etc/zabbix/zabbix_server.conf"
	"/etc/zabbix/php-fpm.conf"
	"/etc/hosts"
	"/etc/hostname"
	"/etc/sudoers.d/ubuntu"
	"/etc/ufw/user.rules"
	"/etc/logrotate.conf"
	"/etc/logrotate.d/zabbix*"								  
)

BACKUP_SERVER=(
	"/root/.msmtprc"
)

GENEARL_INCLUDE=(
	"/home/ubuntu/.ssh/"
	"/home/ubuntu/.ssh/authorized_keys"
	#"/root/.ssh/authorized_keys"
	"/var/spool/cron/crontabs/ubuntu"
	"/etc/hosts"
	"/etc/hostname"
	"/etc/sudoers"
	"/etc/sudoers.d/"
	"/etc/ufw/user.rules"
	"/etc/logrotate.conf"
	"/etc/logrotate.d/si_pos_app"
	"/etc/logrotate.d/si_ecomm_app"
	"/etc/logrotate.d/si_si_app"
)

GENEARL_EXCLUDES=(
#	"--exclude=*/node_modules/*" 
#	"--exclude=*/vendor/*" 
#	"--exclude=*/vendor_*/*" 
#	"--exclude=*/system/*" 						
	"--exclude=*/logs/*"
	"--exclude=*.gz"
	"--exclude=*.zip"
	"--exclude=*.log"
	"--exclude=*.logs"
	"--exclude-backups"
) 

############################################################# DB host, Schema detials #############################################################
# DB_NAME,DB_USER,DB_PASS,DB_HOSTNAME
# NOTE do not use comma in DB_PASS
# List developement servers detials here
dbbackup_user="dbbackup"
dbbackup_pass='q&Dre_FBs97za0rJ'
DEV_DB_INFO_LIST=(
#	"kdiamonddev,$dbbackup_user,$dbbackup_pass,sidevdb.saralideas.com"
	"offlinemfm,$dbbackup_user,$dbbackup_pass,sidevdb.saralideas.com"
	"offlinecdb12,$dbbackup_user,$dbbackup_pass,sidevdb.saralideas.com"
	"ecomm,$dbbackup_user,$dbbackup_pass,sidevdb.saralideas.com"
	"myfamilymartpos,$dbbackup_user,$dbbackup_pass,sidevdb.saralideas.com"
	"middleware10,$dbbackup_user,$dbbackup_pass,sidevdb.saralideas.com"
	"zabbix_db,$dbbackup_user,$dbbackup_pass,srvrmon.saralideas.com"
)

#List Production servers detials here
PROD_DB_INFO_LIST=(
#	"kdiamonddev01,$dbbackup_user,$dbbackup_pass,siproddb.saralideas.com"
	"mfdb01,$dbbackup_user,$dbbackup_pass,siproddb.saralideas.com"
	"cdb01,$dbbackup_user,$dbbackup_pass,siproddb.saralideas.com"
	"middleware,$dbbackup_user,$dbbackup_pass,siproddb.saralideas.com"
	"mfmposlive,$dbbackup_user,$dbbackup_pass,siproddb.saralideas.com"
	"myfamilymart,$dbbackup_user,$dbbackup_pass,siproddb.saralideas.com"
)

############################################################# Backup log Folder on Server #############################################################
# Backup directory
BACKUP_ROOT_DIR="/backup/daily"

#Absolute path of the log directory or relative path from the location the script runs
ERROR_LOG_DIR="/var/www/html/bbc/logs"
REMOTE_TEMP_BACKUP_DIR="/backup"
DB_EXPORT_LOG="$ERROR_LOG_DIR/DB_export.log"
TAR_LOG="$ERROR_LOG_DIR/backup_tar.log"
RUN_LOG="$ERROR_LOG_DIR/backup$RUN_TIME.log"


############################################################# Storage service and credentials ############################################################# 
#### For Hetzner storage box use REMOTE_STORAGE_TYPE = $HETZNER_STORAGE_BOX
#### For AWS S3 Storage use REMOTE_STORAGE_TYPE = $AWS_S3_STORAGE
#commands need to run on server if not able to do rcync
#ssh-keygen
#cat ~/.ssh/id_rsa.pub | ssh -p23 u363914@u363914.your-storagebox.de install-ssh-key
#
#
#
#Required Applications on server
#sshpass
#apt install sshpass
#
HETZNER_STORAGE_BOX="STORAGE_BOX"
AWS_S3_STORAGE="S3"
REMOTE_STORAGE_TYPE=$HETZNER_STORAGE_BOX

## Hetzner storage box details 
SSH_PASS="JsNbDGeLMRiJJWaF"
HETZNER_USER="u363914"
HETZNER_HOST="u363914.your-storagebox.de"
HETZNER_DIR="backup/Daily"

## AWS S3 Storage details 
## to be implemented

############################################################# EMAIL Service credentials #############################################################
#
#For mail configuration you can follow below steps
# apt-get install mailutils
# apt-get install msmtp msmtp-mta
# nano ~/.msmtprc
#  defaults
#  auth           on
#  tls            on
#  tls_trust_file /etc/ssl/certs/ca-certificates.crt
#  logfile        ~/.msmtp.log
#  account        HostingDuty
#  host           smtp52.mailservice25.com
#  port           587
#  from           HostingDuty Support
#  user           support@hostingduty.email
#  password       Welcome@123
#  account default : HostingDuty
