blob: 48651fe5b7b6964a47321add48aad1bcc4cad041 (
plain)
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
|
#!/bin/bash
# script for recreating all dbs
# useful after a node gets added or removed from the cluster
# because there's no automatic rebalancing of bigcouch atm (2013/08)
# One workaround is to recreate all dbs and restore from a backup,
# then all current cluster nodes get recognized
#
# For each db the following main steps are processed:
# 1. replicate db to tmp_db
# 2. delete db, create db
# 3. replicate tmp_db to db
# concurrent replication might cause stalled tasks, see #https://leap.se/code/issues/3506,
# so we use slower, sequential replication here
. couchdb_scripts_defaults.conf
. couchdb_functions
dbs="`get_dbs $URL`"
# concurrent replication might cause stalled tasks, see #https://leap.se/code/issues/3506
for db in $dbs
do
tmpdb="${TMPPREFIX}_${db}"
echo -e "\n\n\nRecreating db $db\n------------------------------\n"
# cleaning potential leftovers from past replications
task="${db}_${tmpdb}"
doc_exists $URL $db $task && ( echo -e "\nDeleting old backup replication task \"$task\" "; delete_doc ${BACKEND_URL} "_replicator" ${task} )
doc_exists $URL $db ${tmpdb}_${db} && ( echo -e "\nDeleting old restore replication task \"${tmpdb}_${db}\" "; delete_doc ${BACKEND_URL} "_replicator" ${tmpdb}_${db} )
db_exists $URL $tmpdb && ( echo -e "\nDeleting old backup db $tmpdb"; delete_db $URL $tmpdb )
# backup, delete, restore
echo -e "\nReplicating $db to $tmpdb"
replicate_db ${auth_url} ${BACKEND_URL} $db $tmpdb
echo -e "\nDeleting $db"
delete_db $URL $db
echo -e "\nRestoring $db"
replicate_db $auth_url ${BACKEND_URL} $tmpdb $db
# clean up
echo -e "\nDeleting backup db $tmpdb"
delete_db $URL $tmpdb
echo -e "\nDeleting backup replication task \"$task\" "
delete_doc ${BACKEND_URL} "_replicator" ${task}
echo -e "\nDeleting restore replication task \"${tmpdb}_${db}\" "
delete_doc ${BACKEND_URL} "_replicator" ${tmpdb}_${db}
done
|