Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64
Your IP : 18.117.254.202
#!/bin/bash
################################################################
##
## MySQL Database Backup Script
## Written By: Rahul Kumar
## URL: https://tecadmin.net/bash-script-mysql-database-backup/
## Last Update: Jan 05, 2019
##
################################################################
export PATH=/bin:/usr/bin:/usr/local/bin
TODAY="$(date +"%d-%m-%Y")"
################################################################
################## Update below values ########################
DB_BACKUP_PATH='bkp/dbbackup'
MYSQL_HOST='logisys2013.cv9maxyrxjgg.ap-south-1.rds.amazonaws.com'
MYSQL_PORT='3306'
MYSQL_USER='admin'
MYSQL_PASSWORD='Logisys$1997'
BACKUP_RETAIN_DAYS=0 ## Number of days to keep local backup copy
#################################################################
declare -a arr=("logisys3_aims" "logisys3_jssstu" "logisys3_dypatil" "logisys3_srun" "logisys3_bcu" "logisys3_bnu" "logisys3_comexam" "logisys3_dud" "logisys3_gach" "logisys3_gcc" "logisys3_gcg" "logisys3_gcm" "logisys3_gcw" "logisys3_gfgcg" "logisys3_gsc" "logisys3_gsh" "logisys3_jssm" "logisys3_jssu" "logisys3_jssw" "logisys3_kswu" "logisys3_kus" "logisys3_kusd" "logisys3_mcu" "logisys3_mum" "logisys3_nehu" "logisys3_nehu_an" "logisys3_nitte" "logisys3_nmamit" "logisys3_nub" "logisys3_oums" "logisys3_rcu" "logisys3_reva" "logisys3_sdu" "logisys3_sikkim" "logisys3_sjvp" "logisys3_ssa" "logisys3_ssc" "logisys3_stph" "logisys3_vku" "logisys3_ruas" "logisys3_sjbit" "logisys3_mfgc" "logisys3_rrit" "logisys3_hcon" "logisys3_msgi" "logisys3_dypatil_bkp" "logisys3_nmamit_bkp" "logisys3_srun_bkp" "logisys3_aims_bkp" "logisys3_jssstu_bkp" "logisys3_sjbit_bkp" "logisys3_adc" "logisys3_aiet" "logisys3_epcet" "logisys3_gss" "logisys3_rpd" "logisys3_surana" "logisys3_jssum" "logisys3_jssun")
chmod -R 777 bkp/
mkdir -p ${DB_BACKUP_PATH}/${TODAY}
for i in "${arr[@]}"
do
echo "Backup started for database - ${i}"
mysqldump -h ${MYSQL_HOST} \
-P ${MYSQL_PORT} \
-u ${MYSQL_USER} \
-p${MYSQL_PASSWORD} \
${i} | gzip > ${DB_BACKUP_PATH}/${TODAY}/${i}-${TODAY}.sql.gz
if [ $? -eq 0 ]; then
echo "Database backup successfully completed"
else
echo "Error found during backup"
fi
aws s3 sync ${DB_BACKUP_PATH}/${TODAY} "s3://logisys-bkps/$TODAY"
file="${DB_BACKUP_PATH}/${TODAY}/${i}-${TODAY}.sql.gz"
if [ -f "$file" ] ; then
rm "$file"
fi
done
##### Remove backups older than {BACKUP_RETAIN_DAYS} days #####
rm -r ${DB_BACKUP_PATH}/${TODAY}
### End of script ####
|