-
Notifications
You must be signed in to change notification settings - Fork 4
/
pull-db.sh
executable file
·61 lines (50 loc) · 1.77 KB
/
pull-db.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
#!/bin/bash
defaultTempFolder="/tmp/pull-db"
read -p "Download folder [$defaultTempFolder]: " tempFolder
tempFolder=${tempFolder:-$defaultTempFolder}
defaultSourceHost=$PULL_DB_DEFAULT_SOURCE_HOST
read -p "Source host [$defaultSourceHost]: " sourceHost
sourceHost=${sourceHost:-$defaultSourceHost}
defaultSourceDb="ebl"
read -p "Database [$defaultSourceDb]: " sourceDb
sourceDb=${sourceDb:-$defaultSourceDb}
defaultSourceUser=$PULL_DB_DEFAULT_SOURCE_USER
defaultSourcePassword=$PULL_DB_DEFAULT_SOURCE_PASSWORD
read -p "Source user name [$defaultSourceUser]: " sourceUser
read -sp "Source password [${defaultSourcePassword//?/*}]: " sourcePassword
sourceUser=${sourceUser:-$defaultSourceUser}
sourcePassword=${sourcePassword:-$defaultSourcePassword}
echo
defaultTargetHost="localhost:27017"
read -p "Target host [$defaultTargetHost]: " targetHost
targetHost=${targetHost:-$defaultTargetHost}
read -p "Target user name (Leave blank if target has no authentication.): " targetUser
if [ $targetUser ]
then
read -sp "Target password:" targetPassword
echo
fi
mkdir -p $tempFolder
mongodump -h $sourceHost \
-d $sourceDb \
--forceTableScan \
--excludeCollection=changelog \
--excludeCollectionsWithPrefix=folios. \
--excludeCollectionsWithPrefix=photos. \
--excludeCollectionsWithPrefix=fragments_ \
--excludeCollectionsWithPrefix=texts_ \
--excludeCollectionsWithPrefix=words_ \
--excludeCollectionsWithPrefix=signs_ \
-u $sourceUser -p $sourcePassword \
--ssl --sslAllowInvalidCertificates \
-o $tempFolder
if [ $targetUser ]
then
mongorestore -h $targetHost \
-u $targetUser -p $targetPassword \
--authenticationDatabase $sourceDb \
--drop \
$tempFolder
else
mongorestore -h $targetHost --drop $tempFolder
fi