-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcouchdb-delete-all.sh
More file actions
executable file
·61 lines (50 loc) · 1.55 KB
/
Copy pathcouchdb-delete-all.sh
File metadata and controls
executable file
·61 lines (50 loc) · 1.55 KB
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
# This removes all the DBs for an instance of CouchDB, usually to replace them for development purposes
# Values to set in Conf file
# HOST=[host] # http://localhost
# PORT=[port] # probably some variant of 5984
# USER=[username] # possibly 'admin'
# PW=[password]
# read in config info, from the config
# file provided, or, if none is provided
# from the default file...
BASE=`basename -s .sh $0`
CONF=./${BASE}.conf
if test -r $CONF ; then
. $CONF
echo "Reading config file: $CONF"
else
echo "Config file $CONF does not exist!"
exit 1
fi
CURL=`which curl`
EXISTING=`$CURL -X GET -H "Content-Type:application/json" ${HOST}:${PORT}/_all_dbs`
echo "Are you sure you want to remove the following databases:\n ${EXISTING}"
echo "On the http://${HOST}:${PORT}"
# requires user input
select yn in "Yes" "No"; do
case $yn in
Yes ) DELETE=true; break;;
No ) exit 1;;
esac
done
# Get the databases
if [ $DELETE ]; then
echo "Deleting $EXISTING..."
for DB in $DBS
do
if [[ ! "$EXISTING" = *"\"${DB}\""* ]]; then
echo "creating $DB"
$CURL -X PUT http://${USER}:${PW}@${HOST}:${PORT}/${DB}
echo "restoring database $DB"
FILES=( ${BUDIR}/${BU}/${DB}-back-*.json )
FILE=${FILES[-1]}
$CURL -d @${FILE} -X POST http://${USER}:${PW}@${HOST}:${PORT}/${DB}/_bulk_docs -H "Content-Type:application/json"
else
echo "$DB already exists, skipping"
fi
done
else
echo "dbnames.txt file NOT found in $BUDIR/$BU"
exit 1
fi