Skip to content

Instantly share code, notes, and snippets.

@ynx0
Last active February 18, 2021 23:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ynx0/0227145d9659d81685374b38dec1f0fb to your computer and use it in GitHub Desktop.
Save ynx0/0227145d9659d81685374b38dec1f0fb to your computer and use it in GitHub Desktop.
helper script for running recovery on an urbit ship. assumes pier is in current directory
#!/bin/bash
DRY_RUN=false
HARD_DELETE=true
#DEL="trash" # use this if you have trash-cli enabled and don't want to risk the script accidently deleting your precious jam files
DEL="rm"
SHIP_NAME=${1:-"sampel-palnet"} # change this or pass it in as a cmdline input
NUM_EVENTS=${2:-1000000} # change this or pass it in as a cmdline input
LATEST_EVENT="$(ls ./$SHIP_NAME/.urb/roc/ | cut -d'.' -f1 | sort -nr | head -n1)"
echo "Checkpoint: $LATEST_EVENT"
echo "Recovering $NUM_EVENTS events on ship $SHIP_NAME."
# process a certain number of events
if [ "$DRY_RUN" = true ]; then
echo ./urbit -r "$LATEST_EVENT" -n "$(($LATEST_EVENT + $NUM_EVENTS))" "$SHIP_NAME"
else
./urbit -r "$LATEST_EVENT" -n "$(($LATEST_EVENT + $NUM_EVENTS))" "$SHIP_NAME"
fi
stty sane # this makes the tty sane lmao
# delete oldest serialized state
JAMCOUNT=$(ls ./"$SHIP_NAME"/.urb/roc/ | wc -l)
if [ $JAMCOUNT -gt 3 ]; then
echo "deleting some jams"
ls ./"$SHIP_NAME"/.urb/roc/ | sort -n | head -n$((JAMCOUNT - 2)) | xargs -I {} "$DEL" ./"$SHIP_NAME"/.urb/roc/{}
fi
@ynx0
Copy link
Author

ynx0 commented Feb 17, 2021

Then, to have the script run multiple times use:

bash

for i in {1..10}; do ./run_replay_recovery; done

zsh

repeat 20 ./run_replay_recovery

@ynx0
Copy link
Author

ynx0 commented Feb 17, 2021

NO WARRANTY! PLEASE DON'T YELL AT ME IF IT BREAKS YOUR SHIP! HOPEFULLY THIS SCARES YOU ENOUGH TO READ THE SCRIPT FIRST!!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment