forked from alaz/backupninja-mongodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmongodb.helper
95 lines (82 loc) · 2.51 KB
/
mongodb.helper
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
# -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
# vim: set filetype=sh sw=3 sts=3 expandtab autoindent:
HELPERS="$HELPERS mongodb:mongodb_database_backup"
do_mongodb_vserver() {
choose_one_vserver "$mongodb_title"
[ $? = 0 ] || return 1
vsname="vsname = $REPLY"
}
mongodb_wizard() {
# Global variables
mongodb_title="MongoDB action wizard"
# backup the host system or a Vserver?
choose_host_or_one_vserver "$mongodb_title"
[ $? = 0 ] || return 1
if [ $host_or_vservers == vservers ]
then
do_mongodb_vserver
[ $? = 0 ] || return 1
fi
inputBox "$mongodb_title" "What is the path to \"mongodump\" utility?" "/usr/bin/mongodump"
[ $? = 1 ] && return;
result="$REPLY"
mongodump="mongodump = $result"
mongouser="# mongouser = <username>"
mongopass="# mongopass = <password>"
inputBox "$mongodb_title" "Mongo DB User"
[ $? = 1 ] && return;
result="$REPLY"
if [ $REPLY ]
then
mongouser="mongouser = $result"
inputBox "$mongodb_title" "Mongo DB Password"
[ $? = 1 ] && return;
result="$REPLY"
mongopass="mongopass = $result"
fi
backupdir_default="/var/backups/mongodb"
mongodb="# mongodb = <db to backup>"
mongocollection="# mongocollection = <collection to backup>"
inputBox "$mongodb_title" "Mongo DB to backup, leave empty for all dbs."
[ $? = 1 ] && return;
result="$REPLY"
if [ $REPLY ]
then
mongodb="mongodb = $result"
backupdir_default="${backupdir_default}_${result}"
inputBox "$mongodb_title" "Mongo collection to backup, leave empty for all collections."
[ $? = 1 ] && return;
result="$REPLY"
if [ $REPLY ]
then
mongocollection="mongocollection = $result"
backupdir_default="${backupdir_default}_${result}"
fi
fi
inputBox "$mongodb_title" "Directory where backups should be stored?`echo \"\n(Relative to the vserver's root if run in a vserver)\"`" $backupdir_default
[ $? = 1 ] && return;
result="$REPLY"
backupdir="backupdir = $result"
inputBox "$mongodb_title" "MongoDB host" "localhost"
[ $? = 1 ] && return;
result="$REPLY"
dbhost="dbhost = $result"
inputBox "$mongodb_title" "MongoDB port" "27017"
[ $? = 1 ] && return;
result="$REPLY"
dbport="dbport = $result"
get_next_filename $configdirectory/31-db.mongodb
cat > $next_filename <<EOF
# when = everyday at 5:15
$mongodump
$mongouser
$mongopass
$mongodb
$mongocollection
$backupdir
$dbhost
$dbport
$vsname
EOF
chmod 600 $next_filename
}