MongoDB BackUp as Zip
Tested on 2.6.0
. zMongoBackUp.sh CRM
#!/bin/sh
Escape="\033";
Reset="${Escape}[0m";
BlackF="${Escape}[30m";
RedF="${Escape}[31m";
GreenF="${Escape}[32m";
YellowF="${Escape}[33m";
zConfirmYesNo () {
zCommand=$*
printf "\n"
printf "${GreenF} '$zCommand' will be executed. Are you sure? [Yes|No]: ${BlueF}Yes ${Reset}"
read zComfirm
if [[ "$zComfirm" =~ ^(y|Y|Yes|YES)$ ]]
then
printf "${RedF} $zCommand ${Reset}\n"
$zCommand
elif [[ "$zComfirm" =~ ^(n|N|No|NO)$ ]]
then
printf "${RedF} $zCommand ${Reset}\n"
else
printf "${RedF} $zCommand ${Reset}\n"
$zCommand
fi
}
mongoBackUp () {
zDatabase=$1
zToday=`date +"%Y_%m_%d-%H-%M-%S"`
zHomeDir=`echo ~`
zBackUpFolder="$zHomeDir/$zDatabase-$ENV-$zToday"
echo $zBackUpFolder
mkdir $zBackUpFolder
zCommand="mongodump --db $zDatabase --out $zBackUpFolder/"
echo $zCommand
zConfirmYesNo $zCommand
zCommand="zip --junk-paths -r $zDatabase-$ENV-$zToday.zip $zBackUpFolder/$zDatabase/"
zConfirmYesNo $zCommand
zCommand="ls -al $zBackUpFolder/$zDatabase/"
zConfirmYesNo $zCommand
zCommand="rm -r $zBackUpFolder/$zDatabase/"
zConfirmYesNo $zCommand
zCommand="rm -r $zBackUpFolder/"
zConfirmYesNo $zCommand
zCommand="ls -l --color=auto $zHomeDir"
$zCommand
}
echo "usage: '. zMongoBackUp.sh CRM'"
printf "\n\n"
zDatabase=$1
mongoBackUp $zDatabase
Created 7 years ago by Ahmet Faruk Bişkinler
Last Updated 7 years ago by Ahmet Faruk Bişkinler