summaryrefslogtreecommitdiff
path: root/bigcouch_compact_all_shards.sh
blob: 82aa3c268801ffcdc0b76424a16c6748f0ca1319 (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
#!/bin/sh -e
#
# script to compact all shards
# 
# released under the terms of the `GNU GPL version 3` or later (see README.md for details)

SHARDSDIR='/opt/bigcouch/var/lib/'
NETRC='/etc/couchdb/couchdb.netrc'
SIZE='1M'

shards=`find ${SHARDSDIR}/shards/ -type f -size +${SIZE}`

echo
echo "Disk usage before: `df -h $SHARDSDIR`" 
echo 

for i in $shards
do
  shard=`echo $i | sed "s/^.*shards\///" | cut -d'/' -f 1`
  db=`basename $i .couch`
  echo -n "compacting ${i}:"
  curl -s -X POST --netrc-file $NETRC -H "Content-Type: application/json" "http://127.0.0.1:5986/shards%2F${shard}%2F${db}/_compact"
  sleep 1
done

echo
echo "Disk usage after: `df -h $SHARDSDIR`" 
echo 

echo "$0 ran successful"