View table-rotation.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- If your table is really large, and it very well may be if you've the need to rotate it, you'll want to make sure the column that holds the timestamp/date is indexed. | |
-- WARNING: This script incurs a write lock for the duration of the trigger recreation and table rename. If your application can't handle this, you might lose data! | |
-- Create our new skeleton table | |
CREATE TABLE x_copy LIKE x; | |
-- Replace the interval with the timespan of data you'd like to keep, or | |
-- replace this statement with one that stores an id in the local variable of which all higher will be retained | |
SELECT MIN(id) INTO @end_id FROM x WHERE created_at >= DATE(NOW()) - INTERVAL 3 WEEK; |
View ordered-mysqldump.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
db_user=username | |
db_pass=password | |
db_schema=schema | |
db_host=hostname | |
db_login="-h$db_host -u$db_user -p$db_pass " | |
# Dump BASE TABLES (not views) | |
echo "Dumping base tables..." |
View kayako-backups.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
storagedir='/root/backups' | |
backupdir='/var/www/__swift/files' | |
s3path='live-kayako-caches/backups/' | |
s3cpath="$(which python) /root/s3cmd-1.5.0-beta1/s3cmd" | |
if [ ! -d ${storagedir} ] ; then mkdir ${storagedir} ; fi | |
cd ${storagedir} | |
curdate=$(date -u '+%Y%m%d') |
View truecrypt-package-verification.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# You might want to change the download url to another if your system is not using the amd64 architecture | |
wget -c -q https://www.grc.com/misc/truecrypt/truecrypt-7.1a-linux-x64.tar.gz | |
TC_CHECKSUM=`sha256sum ./truecrypt-7.1a-linux-x64.tar.gz | awk '{print $1}'` | |
TC_VERIFIED_CHECKSUM=`curl -s https://defuse.ca/downloads/truecrypt-hashes.asc | grep -A19 -i sha256 | grep 'truecrypt-7.1a-linux-x64.tar.gz$' | awk '{print $1}'` | |
if [ -n "${TC_VERIFIED_CHECKSUM}" ] ; then | |
if [ "${TC_CHECKSUM}" == "${TC_VERIFIED_CHECKSUM}" ] ; then | |
tar xfz truecrypt-7.1a-linux-x64.tar.gz |
View inititalize-mysql.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -e | |
# This is a draft and may not work for you. | |
# Dependencies: | |
# - aws python cli toolset | |
# - qpress / quicklz | |
# - s3-mutlipart.py | |
# Search an array for an element | |
## http://stackoverflow.com/a/8574392/2272443 |
View replication_check.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Monitor and report a status code somewhere about a MySQL slave's replication connection | |
# Useful for when traditional monitoring cannot be achieved due to firewalling. | |
D=`date -u +"%Y%m%d%H%M"` | |
mysqlparams='-h... -ureplicator -p...' | |
query='show slave status\G' | |
logfile='/var/log/replication_check.log' |
View luks-helper.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Description: | |
# Take action to secure an open LUKS container | |
# Helpful when bound to a keyboard shortcut in your favorite DE/WM | |
# DISCLAIMER: | |
# Must be ran as root - take care in securing access to this script | |
# I added a selective line to /etc/sudoers.d such as: | |
# %wheel ALL=(ALL) NOPASSWD: /bin/bash /path/to/script/ close /path/to/mountpoint |
View backup-ec2.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# INVOCATION: bash $0 | |
# LOG LOCATION: $storagedir/$prefix-DATESTAMP.log | |
# NOTES: | |
# - Install this in your crontab on an appropriate schedule. Filenames are to minute resolution. | |
# - Depending on the method in which AWS CLI was installed, it may not be in $PATH when cron executes. This will be evident in your local user mail and the script log | |
# CONFIGS | |
storagedir="$HOME/backups" |
View commands.cfg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I've only included the two command additions to the this commands.cfg file | |
# 'notify-host-by-push' command definition | |
define command{ | |
command_name notify-host-by-push | |
command_line /usr/bin/curl --header 'Authorization: Bearer <your_access_token_here>' -X POST https://api.pushbullet.com/v2/pushes --header 'Content-Type: application/json' --data-binary '{"type": "note", "title": "* $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **", "body": "***** Nagios ***** Notification Type: $NOTIFICATIONTYPE$ Host: $HOSTNAME$ State: $HOSTSTATE$ Address: $HOSTADDRESS$ Info: $HOSTOUTPUT$ Date/Time: $LONGDATETIME$", "email": "<email_associated_with@pushbullet-account.here>"}' | |
} | |
# 'notify-service-by-push' command definition - ident | |
define command{ |
View mysql2file.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
from sys import argv | |
import csv | |
import MySQLdb | |
from MySQLdb import cursors | |
mysql_params = [argv[1], argv[2], argv[3], argv[4], argv[5]] | |
output_file = argv[6] | |
mysql_query = argv[7] |
OlderNewer