Skip to content

Instantly share code, notes, and snippets.

@olavmrk
olavmrk / lvm-daily-snapshot.sh
Created December 11, 2013 13:24
A script to take daily snapshots of a LVM volume.
#!/bin/bash
KEEP_DAYS=15
VG="vg" # LVM volume group we are snapshoting
LV="data-volume-name" # Name of LVM-volume to take a snapshot of
BACKUP_PREFIX="backup-volume-prefix-" # Prefix of snapshot volume name.
SIZE=40G # Amount of disk space to allocate for the snapshot
# Create new snapshot
@olavmrk
olavmrk / resume-devs.sh
Created December 11, 2013 13:28
Script to resume suspended LVM volumes, due to Debian bug #659762: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=659762 The script must most likely be executed multiple times to recover all suspended volumes.
#!/bin/bash
dmsetup info | while IFS=: read NAME VALUE; do
# Trim leading and trailing whitespace from NAME and VALUE
NAME="$(echo "$NAME" | sed -e 's/^ *//g' -e 's/ *$//g')"
VALUE="$(echo "$VALUE" | sed -e 's/^ *//g' -e 's/ *$//g')"
if [ -z "$NAME" ]; then
continue
fi
#!/usr/bin/env python
import socket
import struct
import sys
src_ip = sys.argv[1]
src_port = int(sys.argv[2])
dst_addr = sys.argv[3]
dst_port = int(sys.argv[4])
@olavmrk
olavmrk / gist:8560126
Last active December 2, 2020 07:47
Archiving a server
# Copy the filesystem:
rsync --numeric-ids --checksum --delete --archive --verbose --exclude /dev --exclude /proc --exclude /run --exclude /sys root@someserver:/ /mnt/tmp
# Create a squashfs image
mksquashfs /mnt/tmp someserver.squashfs -comp xz -noappend
# Create LVM volume
lvcreate --size $(stat --format %s someserver.squashfs)B --name old-someserver vg
# Archive image on LVM
#!/usr/bin/env python
import select
import socket
import struct
import sys
TIMEOUT = 10.0
ip = sys.argv[1]
port = int(sys.argv[2])
@olavmrk
olavmrk / removeexcept.sh
Last active August 23, 2021 21:33
git filter-branch command to remove all files except those of interest
# Remove every file except "./somefile.txt" and the directory "./somedir".
# --prune-empty to remove empty commits.
git filter-branch --tree-filter "find . -not -path './.git' -not -path './.git/*' -not -path './somefile.txt' -not -path './somedir/*' -not -path './somedir' -delete" --prune-empty
@olavmrk
olavmrk / removeparent.sh
Last active August 29, 2015 13:57
Remove all parents from commit
# Remove parent of commit 9c747fd659803ab7406b55fe38f752a03b9157d3
git filter-branch --parent-filter 'test $GIT_COMMIT = "9c747fd659803ab7406b55fe38f752a03b9157d3" || cat' HEAD
@olavmrk
olavmrk / check_openssl_wheezy.py
Last active August 29, 2015 13:58
Simple tool to check for processes using deleted versions of openssl, and trying to identify services needing a restart
#!/usr/bin/env python2
import os
import re
import sys
vulnerable = frozenset([
'/usr/lib/i386-linux-gnu/i686/cmov/libssl.so.1.0.0',
'/usr/lib/x86_64-linux-gnu/libssl.so.1.0.0',
])
#include <asm/types.h>
#include <linux/netlink.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
int main() {
int res;
@olavmrk
olavmrk / statictest.py
Created June 29, 2014 18:04
Testing storing references to @staticmethod in class
#!/usr/bin/env python
class Hello(object):
@staticmethod
def _hello_impl_1():
print 'Hello world!'
_hello_impl = None
@staticmethod
def hello():
if Hello._hello_impl == None:
Hello._hello_impl = Hello._hello_impl_1