Skip to content

Instantly share code, notes, and snippets.

View fdv's full-sized avatar
🚀
Taking over the world

Fred de Villamil fdv

🚀
Taking over the world
View GitHub Profile
@fdv
fdv / git-commands.sh
Last active August 29, 2024 09:57
A few useful git commands
# in /usr/local/bin/git-cleanup-merged
#!/bin/sh
#!/usr/bin/env bash
current_branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
if [ "$current_branch" != "master" ] && [ "$current_branch" != "main" ]; then
echo "WARNING: You are on branch $current_branch, NOT master or main."
fi
@fdv
fdv / delete-tweets.rb
Created April 16, 2017 08:42
Delete tweets you don't want anymore
# Before running that script, use Twitter backup CSV file to pick up the tweets
# you want to delete. Save, then run:
# cat tweets.csv | cut -f 2 -d '"' | grep '^[0-9]*$' | sed '/^$/d' > delete.csv
# gem install twitter (in case you miss the gem already)
require 'twitter'
client = Twitter::REST::Client.new do |config|
config.consumer_key = ''
config.consumer_secret = ''
while true; do curl -XGET 'cluster:9200/_cat/thread_pool?v&h=host,search.queue,search.active,search.rejected,search.completed' | sort -unk 2,3 ; sleep 5 ; done
@fdv
fdv / esrestart.sh
Created November 4, 2016 18:08
Elasticsearch restart config
# normal
curl -XPUT 'http://esmaster01.:9200/_cluster/settings' -d '{
"transient" : {
"cluster.routing.allocation.cluster_concurrent_rebalance": 50,
"indices.recovery.concurrent_streams": 50,
"cluster.routing.allocation.node_initial_primaries_recoveries": 50,
"cluster.routing.allocation.node_concurrent_recoveries": 50,
"indices.recovery.max_bytes_per_sec": "2048mb",
"cluster.routing.allocation.disk.threshold_enabled" : true,
"cluster.routing.allocation.disk.watermark.low" : "70%",
# Mass index deletion with pattern
for index in $(curl -XGET esmaster:9200/_cat/indices | grep pattern | awk '{print $3}'); do curl -XDELETE esmaster:9200/$index?master_timeout=120s; done
# Mass optimize, indexes with the most deleted docs first
for indice in $(CURL -XGET esmaster:9200/_cat/indices | sort -rk 7 | awk '{print $3}'); do curl -XPOST http://esmaster:9200/${indice}/_optimize?max_num_segments=1; done
# Restart half a cluster using rack awareness
curl -XPUT 'host:9200/_cluster/settings' -d '{ "transient" : { "cluster.routing.allocation.enable": "none" }}'; for host in $(curl -XGET esmaster:9200/_cat/nodeattrs?attr | grep rack_id | awk '{print $2}'); do ssh $host service elasticsearch restart; done; sleep60; curl -XPUT 'host:9200/_cluster/settings' -d '{ "transient" : { "cluster.routing.allocation.enable": "all }}'
#!/bin/sh
HOST=$1
CURL_BIN=$(which curl)
if [ -z "$HOST" ]; then
echo "Host is missing"
exit 1
fi
@fdv
fdv / optimize.sh
Created February 20, 2016 16:27
Rolling optimize of an ElasticSearch cluster
#!/bin/sh
HOST=$1
CURL_BIN=$(which curl)
if [ -z "$HOST" ]; then
echo "Host is missing"
exit 1
fi
@fdv
fdv / es-cheat-sheet.md
Last active February 2, 2021 14:44
An ElasticSearch management cheat sheet

These are the snippets I use most of the time when administrating my ES cluster

To be updated

Settings to change before you do something

Before restarting a data node

curl -XPUT 'http://escluster:9200/_cluster/settings' -d '{

Keybase proof

I hereby claim:

  • I am fdv on github.
  • I am fdevillamil (https://keybase.io/fdevillamil) on keybase.
  • I have a public key whose fingerprint is 3D32 E128 E5D6 4BD8 8CD6 7C1E 2605 FF1F 042D 9183

To claim this, I am signing this object:

@fdv
fdv / backup.sh
Created September 11, 2015 15:02
#!/bin/bash -x
#Tue Jul 2 15:32:21 CEST 2013
#Made by Edward Z.
set -e #stops execution if a variable is not set
set -u #stop execution if something goes wrong
usage() {
echo "usage: $(basename $0) [option]"
echo "option=full: do a full backup of vinnie /var/lib/mysql using innobackupex, aprox time 6 hours."
echo "option=incremental: do a incremental backup"