Skip to content

Instantly share code, notes, and snippets.

View magnetikonline's full-sized avatar
💡
I have an idea!

Peter Mescalchin magnetikonline

💡
I have an idea!
View GitHub Profile
@magnetikonline
magnetikonline / README.md
Last active February 25, 2018 07:15
Transfer MySQL databases between AWS RDS instances.

Transfer MySQL databases between AWS RDS instances

The situation

  • Two AWS RDS MySQL databases - moving databases from source to destination.
  • Both databases are not publicly accessible, only via an EC2 instance(s) - e.g. you have setup your security groups.
  • Can SSH to a target EC2 instance (but of course).

What it does

  • Sets up two SSH port forwards on local machine - one to source database, another to target.
  • Via calls to transferDatabase():
@magnetikonline
magnetikonline / README.md
Last active September 13, 2017 17:18
Using BFG to clean out old binary assets from Git repository.

Using BFG to clean out old binary assets from Git repository

Reference: http://rtyley.github.io/bfg-repo-cleaner/

Example

$ wget http://repo1.maven.org/maven2/com/madgag/bfg/1.11.8/bfg-1.11.8.jar
$ git clone [email protected]:org-name/repo-name.git repo-name.cleanup
$ java -jar bfg-1.11.8.jar --delete-files '*.{gif,jpg,png}' repo-name.cleanup
$ cd repo-name.cleanup
$ git gc --prune=now --aggressive
@magnetikonline
magnetikonline / README.md
Last active October 26, 2023 05:10
AWS CLI S3 usage examples.
@magnetikonline
magnetikonline / clone.sh
Created October 21, 2014 22:57
Git shallow clone repository and any sub-modules within.
#!/bin/bash
git clone --depth 1 \
-qb $BRANCH_NAME \
$REPOSITORY_URL $TARGET_CLONE_DIR
cd $TARGET_CLONE_DIR
git submodule update -q --init --depth 1
@magnetikonline
magnetikonline / addoneday.sh
Created October 8, 2014 09:37
Add one day to file modification time on a collection of files in bash.
#!/bin/bash
find . -type f -exec touch -r "{}" -d '+1 day' "{}" \;
@magnetikonline
magnetikonline / README.md
Created September 29, 2014 21:41
Extract unique HTTP request lines from access.log.

Extract unique HTTP request lines from access.log

$ cat access.log \
	| grep "] \"GET /wp-content/themes/" \
	| awk '{print $7}' \
	| sort -u
@magnetikonline
magnetikonline / README.md
Last active May 18, 2018 17:23
Ensure HTTP redirects are not cached by client browser.

Ensure HTTP redirects are not cached

Chrome (at least) likes to cache HTTP redirects, an issue if you are running logging/reporting on those redirect actions server side. Combat this with some HTTP headers.

Location: http://domain.com/redirect
Cache-Control: must-revalidate,no-cache,no-store
Expires: Sat, 01 Jan 2000 00:00:00 GMT

Or in PHP land that could be...

@magnetikonline
magnetikonline / README.md
Last active December 25, 2018 13:03
SSH forward local port to remote AWS RDS MySQL instance.

SSH forward local port to remote AWS RDS instance

The scenario:

  • We have connectivity to remote server (EC2 instance) REMOTE_EC2_HOST over SSH.
  • Connectivity to AWS RDS MySQL instance RDS.ENDPOINT.rds.amazonaws.com from remote server only (due to security group/firewall settings).
# forward requests from 127.0.0.1:6400 -> RDS.ENDPOINT.rds.amazonaws.com:3306
# add [-f] switch to background ssh process
$ ssh -vvvN \
	-L 6400:RDS.ENDPOINT.rds.amazonaws.com:3306 \
@magnetikonline
magnetikonline / README.md
Last active August 29, 2015 14:06
AWS summary of EC2 storage types.

AWS summary of EC2 storage types

For my own sanity, as I always seem to struggle with this.

Elastic block store (EBS)

  • Can be attached to any EC2 instance in the same availability zone.
  • Recommended for long term persistence.
  • Can attach multiple EBS volumes to a single EC2 instance.
  • Survives reboot, stop/start and terminate (but only if not the root EBS volume).

Instance storage (ephemeral)

@magnetikonline
magnetikonline / README.md
Last active July 14, 2021 13:51
Nginx 1.20.1 modules.