aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Garzik <jgarzik@exmulti.com>2013-02-10 21:02:12 -0800
committerJeff Garzik <jgarzik@exmulti.com>2013-02-10 21:02:12 -0800
commite48aa6076ae6d8d5ff254649216190f8e3ae95b0 (patch)
tree06a10df0dcc9d1e678f09eaefb06f42d73187693
parentf166e0dd2f217641a283b8c8896656c755812f26 (diff)
parent33c055c4f1eca07bd914a5b40a21f92ad82dde9f (diff)
Merge pull request #2295 from sipa/tidydir
Add script to clean up datadirs
-rwxr-xr-xcontrib/tidy_datadir.sh59
1 files changed, 59 insertions, 0 deletions
diff --git a/contrib/tidy_datadir.sh b/contrib/tidy_datadir.sh
new file mode 100755
index 0000000000..5d6d826444
--- /dev/null
+++ b/contrib/tidy_datadir.sh
@@ -0,0 +1,59 @@
+#!/bin/bash
+
+if [ -d "$1" ]; then
+ cd "$1"
+else
+ echo "Usage: $0 <datadir>" >&2
+ echo "Removes obsolete Bitcoin database files" >&2
+ exit 1
+fi
+
+LEVEL=0
+if [ -f wallet.dat -a -f addr.dat -a -f blkindex.dat -a -f blk0001.dat ]; then LEVEL=1; fi
+if [ -f wallet.dat -a -f peers.dat -a -f blkindex.dat -a -f blk0001.dat ]; then LEVEL=2; fi
+if [ -f wallet.dat -a -f peers.dat -a -f coins/CURRENT -a -f blktree/CURRENT -a -f blocks/blk00000.dat ]; then LEVEL=3; fi
+if [ -f wallet.dat -a -f peers.dat -a -f chainstate/CURRENT -a -f blocks/index/CURRENT -a -f blocks/blk00000.dat ]; then LEVEL=4; fi
+
+case $LEVEL in
+ 0)
+ echo "Error: no Bitcoin datadir detected."
+ exit 1
+ ;;
+ 1)
+ echo "Detected old Bitcoin datadir (before 0.7)."
+ echo "Nothing to do."
+ exit 0
+ ;;
+ 2)
+ echo "Detected Bitcoin 0.7 datadir."
+ ;;
+ 3)
+ echo "Detected Bitcoin pre-0.8 datadir."
+ ;;
+ 4)
+ echo "Detected Bitcoin 0.8 datadir."
+ ;;
+esac
+
+FILES=""
+DIRS=""
+
+if [ $LEVEL -ge 3 ]; then FILES=$(echo $FILES blk????.dat blkindex.dat); fi
+if [ $LEVEL -ge 2 ]; then FILES=$(echo $FILES addr.dat); fi
+if [ $LEVEL -ge 4 ]; then DIRS=$(echo $DIRS coins blktree); fi
+
+for FILE in $FILES; do
+ if [ -f $FILE ]; then
+ echo "Deleting: $FILE"
+ rm -f $FILE
+ fi
+done
+
+for DIR in $DIRS; do
+ if [ -d $DIR ]; then
+ echo "Deleting: $DIR/"
+ rm -rf $DIR
+ fi
+done
+
+echo "Done."