-
Notifications
You must be signed in to change notification settings - Fork 1
/
mongo.sh
106 lines (97 loc) · 3.57 KB
/
mongo.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#! /bin/bash
clear
i="y"
while [ $i = "y" ]
do
echo " ___ _____ ____ ____ ___ ____ __ _ _ ____ "
echo "/ __)( _ )( ___)(_ _)/ __)( _ \ /__\ ( \( )( _ \ "
echo "\__ \ )(_)( )__) )( ( (_-. ) / /(__)\ ) ( )(_) )"
echo "(___/(_____)(__) (__) \___/(_)\_)(__)(__)(_)\_)(____/"
echo "1.BackUp Mongo"
echo "2.Backup All Databases"
echo "3.Backup Single Collection"
echo "4.Restore MongoDB Database"
echo "5.Open TCP ports"
echo "6.exit"
echo "7.install mongo-tools DebianOS"
echo "8.install mongo-tools CentOS"
echo "======================================================"
read ch
if [ $ch == "1" ]
then
echo "--------------------------BackUp Mongo------------------------------------------------"
echo "path backup:"
read backupDir
TODAY=`date +%d%b%Y`
BACKUP_DIR=$backupDir
echo "database name:"
read databasename
echo -ne '##### (33%)\r'
sleep 1
echo -ne '############# (66%)\r'
sleep 1
echo -ne '####################### (100%)\r'
echo -ne '\n'
mongodump --db $databasename --out ${BACKUP_DIR}/${TODAY}
echo "=====================done========================="
elif [ $ch == "2" ]; then
echo "--------------------------BackUp Mongo All Database------------------------------------------------"
echo "path backup:"
read backupDir
TODAY=`date +%d%b%Y`
BACKUP_DIR=$backupDir
echo -ne '##### (33%)\r'
sleep 1
echo -ne '############# (66%)\r'
sleep 1
echo -ne '####################### (100%)\r'
echo -ne '\n'
mongodump --out ${BACKUP_DIR}/${TODAY}
echo "=====================done========================="
elif [ $ch == "3" ]; then
echo "--------------------------BackUp Mongo All Database------------------------------------------------"
echo "path backup:"
read backupDir
TODAY=`date +%d%b%Y`
BACKUP_DIR=$backupDir
echo "database name:"
read databasename
echo "Collection Name:"
read collectionName
echo -ne '##### (33%)\r'
sleep 1
echo -ne '############# (66%)\r'
sleep 1
echo -ne '####################### (100%)\r'
echo -ne '\n'
mongodump --collection $collectionName --db $databasename --out ${BACKUP_DIR}/${TODAY}
echo "=====================done========================="
elif [ $ch == "4" ]; then
echo "--------------------------Restore Mongo Database------------------------------------------------"
echo "path backup:"
read backupDir
TODAY=`date +%d%b%Y`
BACKUP_DIR=$backupDir
echo "database name:"
read databasename
echo -ne '##### (33%)\r'
sleep 1
echo -ne '############# (66%)\r'
sleep 1
echo -ne '####################### (100%)\r'
echo -ne '\n'
mongorestore --db $databasename --drop ${BACKUP_DIR}/${TODAY}/$databasename
echo "=====================done========================="
elif [ $ch == "5" ]; then
echo "-------------------------Open TCP ports--------------------------------------------"
nmap -p- -T4 127.0.0.1
echo "-----------------------------------------------------------------------------------"
#statements
elif [ $ch == "6" ]; then
clear;exit;
elif [ $ch == "7" ]; then
sudo apt install mongo-tools
elif [ $ch == "8" ]; then
yum install mongo-tools
fi
done