Archive for the ‘Bash’ Category

Delete all but the most recent files in Bash

I’ve been reviewing a few things I do and decided I need to be a bit smarter about managing backups. I currently purge by date only. Which is fine if everything is working and checked regularly. I wouldn’t want to return from a two week holiday to find my backups had been failing, nobody checked […]

Recover a single table from a mysqldump

I needed to recover the data, from a single table, from a mysqldump containing all the databases from an entire instance. A quick google yielded this result. This produced a nifty little sed one-liner… ?View Code BASHsed -n -e ‘/CREATE TABLE.*your_table_name/,/CREATE TABLE/p’ mysqldump_file.sql > your_table_name.sql I also wanted to import the data into a different […]

mmo: bash script to launch a MongoDB cluster

As I announced in my Technical Goals for 2016 I’m building tools for MongoDB with Python. My first published item is a bash script to create a MongoDB cluster. This cluster will be used to develop, and test, the tools against. It is not intended for any use other than this. The script lives over on […]

Progress bars in BASH with pv

Way back in 2009 I wrote a post about how to display progress bars in Powershell. The same thing is possible in bash with pv. If it’s not available in your shell just do… ?View Code BASHyum install pv Or equivalent for your platform. The following example compresses a file into a tar archive reporting […]

Launch a MongoDB Cluster for testing

Here’s a bash script I use to create a sharded MongoDB Cluster for testing purposes. The key functions are mongo_setup_cluster and mongo_teardown_cluster. The script will created a Mongo Cluster with 2 shards, with 3 nodes each, 3 config server and 3 mongos servers. UPDATE 2015/10/02 I’ve found out about an undocumented option available to set […]