This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bd_backup.sh
43 lines (37 loc) · 2.44 KB
/
bd_backup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
###############################################################################################
# Script que configura o backup automático para o BD #
# #
# Precisa que as variáveis de ambiente USER_BD e PASS_BD estejam definidas, #
# como o usuário e senha para conexão com banco, respectivamente. #
# #
# Para configurar o backup, você deve: #
# 1- Executar sudo crontab -e #
# 2- Adicionar esta linha ao final do arquivo: #
# 00 02 * * * {base_projeto}/bd_backup.sh #
# #
# O backup ocorrerá todos os dias as 02:00 #
# #
# Para criar o usuário do mongo: #
# 1. Acesse o bd, execute "use admin" #
# 2. db.createUser({ user: "{USUARIO}", pwd: "{SENHA}", #
# roles: [{ role: "root", db: "admin" }]}) #
# https://stackoverflow.com/questions/38921414/mongodb-what-are-the-default-user-and-password # #
# #
###############################################################################################
if [[ -z $USER_BD ]]; then
echo ">> Usuário não definido para a conexão com o BD."
exit 1
fi
if [[ -z $PASS_BD ]]; then
echo ">> Senha não definida para a conexão com o BD."
exit 1
fi
DIR_BACKUP="./mongo_backup"
DIR_TEMP=$DIR_BACKUP"_temp"
mkdir $DIR_TEMP
echo ">> Iniciando dump"
mongodump -h 127.0.0.1:27017 -d SCORE -u $USER_BD -p $PASS_BD -o $DIR_TEMP --authenticationDatabase admin
echo ">> Dump finalizado."
rm -rf $DIR_BACKUP
mv $DIR_TEMP $DIR_BACKUP
rm -rf $DIR_TEMP