Skip to content

Instantly share code, notes, and snippets.

@viertelb
Created November 25, 2020 15:21
Show Gist options
  • Save viertelb/cb7aca6572f1981397ccbce81f78948e to your computer and use it in GitHub Desktop.
Save viertelb/cb7aca6572f1981397ccbce81f78948e to your computer and use it in GitHub Desktop.
#!/bin/bash
# moveblockstoHDD.sh
# Moves blocks from SSD to HDD
set -e
BLK_TARGET=/mnt/omv/blocks
WORKDIR=/mnt/bitcoin/bitcoin/blocks
# How many files to move PER TYPE
LIMIT=100
echo "Did you stop bitcoind, lnd and electrs?"
sleep 2
echo "Will move blocks to: $BLK_TARGET"
echo "Are you user bitcoin? wohami:"
whoami
sleep 2
echo "Test if $BLK_TARGET is mounted"
ls $BLK_TARGET
echo "Did it print blocks?"
echo "Now moving "$LIMIT" files per filetype"
echo "You have 10 seconds to quit with CTRL-C"
sleep 10
echo "Using workdir: "$WORKDIR
cd $WORKDIR
function dryrun {
((++COUNT))
echo $COUNT
echo $line
echo 'Link remote file' "$BLK_TARGET/$line" ' as local '"$WORKDIR/$line"
if [[ $COUNT == $LIMIT ]]; then
break
fi
}
function movefiles {
((++COUNT))
echo $line
cp -u "$WORKDIR/$line" "$BLK_TARGET/$line"
rm "$WORKDIR/$line"
ln -s "$BLK_TARGET/$line" "$WORKDIR/$line"
if [[ $COUNT == $LIMIT ]]; then
break
fi
}
function findandmove {
COUNT=0
echo "----------------------------- find "$FILENAME -----------------------
sleep 2
find "$WORKDIR" -name "$FILENAME" -type f -printf '%f\n' | sort > tomove
while read line; do
dryrun
# movefiles
done <tomove
rm tomove
}
FILENAME='blk*.dat'
findandmove
FILENAME='rev*.dat'
findandmove
echo Done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment