Initial commit
authorMegaBrutal <code+git@megabrutal.com>
Tue, 4 Aug 2015 02:23:54 +0000 (04:23 +0200)
committerMegaBrutal <code+git@megabrutal.com>
Tue, 4 Aug 2015 02:23:54 +0000 (04:23 +0200)
 Changes to be committed:
new file:   fs/backup_check.sh
new file:   fs/backup_check_FreeBSD.sh
new file:   fs/backup_diff.sh
new file:   fs/backup_full.sh
new file:   fs/snapshot-rootfs.sh
new file:   host/check-fs-usage.sh
new file:   host/vmhost-status.sh
new file:   mysql/backup.sh
new file:   mysql/mysqlbak_check.sh
new file:   smf/check_smf_pending_users.sh
new file:   smf/mail_user_profile.sh
new file:   smf/smf_fetch_user_profile.sh

12 files changed:
fs/backup_check.sh [new file with mode: 0755]
fs/backup_check_FreeBSD.sh [new file with mode: 0755]
fs/backup_diff.sh [new file with mode: 0644]
fs/backup_full.sh [new file with mode: 0644]
fs/snapshot-rootfs.sh [new file with mode: 0755]
host/check-fs-usage.sh [new file with mode: 0755]
host/vmhost-status.sh [new file with mode: 0755]
mysql/backup.sh [new file with mode: 0755]
mysql/mysqlbak_check.sh [new file with mode: 0755]
smf/check_smf_pending_users.sh [new file with mode: 0755]
smf/mail_user_profile.sh [new file with mode: 0644]
smf/smf_fetch_user_profile.sh [new file with mode: 0755]

diff --git a/fs/backup_check.sh b/fs/backup_check.sh
new file mode 100755 (executable)
index 0000000..06746cc
--- /dev/null
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+if [ "$#" -eq "0" ]
+then
+       echo "Usage: $0 backup_directory"
+       exit 1
+fi
+
+BAKDIR=$1
+
+cd ${BAKDIR}
+
+echo CHECKING ${BAKDIR}:
+ls -l
+
+ls -1 *.md5 | while read sumfile
+do
+       echo
+       echo ${sumfile}:
+       cat ${sumfile}
+       echo
+       # /sbin/md5 -r $(cat ${sumfile} | cut -f2 -d"*") | sed "s/ / */g" | diff - ${sumfile}
+       md5sum -c ${sumfile}
+       echo MD5SUM return value: $?
+done
diff --git a/fs/backup_check_FreeBSD.sh b/fs/backup_check_FreeBSD.sh
new file mode 100755 (executable)
index 0000000..111a3b3
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+if [ "$#" -eq "0" ]
+then
+       echo "Usage: $0 backup_directory"
+       exit -1
+fi
+
+BAKDIR=$1
+
+cd ${BAKDIR}
+
+echo CHECKING ${BAKDIR}:
+ls -l
+
+ls -1 *.md5 | while read sumfile
+do
+       echo
+       echo ${sumfile}:
+       cat ${sumfile}
+       echo
+       /sbin/md5 -r $(cat ${sumfile} | cut -f2 -d"*") | sed "s/ / */g" | diff - ${sumfile}
+       echo Diff return value: $?
+done
diff --git a/fs/backup_diff.sh b/fs/backup_diff.sh
new file mode 100644 (file)
index 0000000..404b5e3
--- /dev/null
@@ -0,0 +1,4 @@
+# PLACEHOLDER FILE!
+# This script is not yet ready for publication, as it contains environment-specific and/or hard-coded sensitive data.
+# This file is here to annoy myself to make an update.
+#      ~ MegaBrutal
diff --git a/fs/backup_full.sh b/fs/backup_full.sh
new file mode 100644 (file)
index 0000000..404b5e3
--- /dev/null
@@ -0,0 +1,4 @@
+# PLACEHOLDER FILE!
+# This script is not yet ready for publication, as it contains environment-specific and/or hard-coded sensitive data.
+# This file is here to annoy myself to make an update.
+#      ~ MegaBrutal
diff --git a/fs/snapshot-rootfs.sh b/fs/snapshot-rootfs.sh
new file mode 100755 (executable)
index 0000000..5b7d05b
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/sh
+mount /btrfs
+/sbin/btrfs subvolume snapshot -r /btrfs/@ /btrfs/@-snapshot-$(date +%Y%m%d%H%M%S)
+umount /btrfs
diff --git a/host/check-fs-usage.sh b/host/check-fs-usage.sh
new file mode 100755 (executable)
index 0000000..3b7cd8d
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+if [ $# -lt 2 ]
+then
+       echo "Usage: $0 <fs> <percentage> [email]"
+       echo "Where"
+       echo "  fs              - file system to check"
+       echo "  percentage      - acceptable file system usage treshold"
+       echo "  email           - send warning to specified e-mail address (print to stdout, if omitted)"
+       echo "Example: $0 / 95 admin@cutekittens.tld"
+       exit
+fi
+
+if [ $(df -m $1 | sed 1d | awk '{print $5}' | sed "s/%//") -ge $2 ]
+then
+       subject="WARNING! File system usage ($1) on $(hostname) is higher than $2 percent!"
+       if [ -z "$3" ]
+       then
+               echo ${subject}
+               df -m
+       else
+               df -m | mail -s "${subject}" $3
+       fi
+fi
diff --git a/host/vmhost-status.sh b/host/vmhost-status.sh
new file mode 100755 (executable)
index 0000000..6e76754
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/sh
+echo SYSTEM INFO:
+uname -a
+echo
+echo SYSTEM UPTIME:
+uptime
+echo
+echo
+echo MEMORY:
+echo
+grep -E "MemTotal|MemFree|SwapTotal|SwapFree" /proc/meminfo
+echo
+echo
+echo UPDATES:
+/usr/lib/update-notifier/update-motd-updates-available --force
+/usr/lib/update-notifier/update-motd-reboot-required
+echo
+echo
+echo FILE SYSTEMS:
+echo
+df -m
+echo
+echo
+echo BTRFS SUBVOLUMES:
+echo
+/sbin/btrfs subvolume list /
+echo
+echo
+echo LXC CONTAINERS:
+echo
+lxc-ls --fancy
+echo
+echo
+echo LIBVIRT VIRTUAL MACHINES:
+echo
+virsh list
diff --git a/mysql/backup.sh b/mysql/backup.sh
new file mode 100755 (executable)
index 0000000..a68853f
--- /dev/null
@@ -0,0 +1,53 @@
+#!/bin/sh
+passfile=$1
+cfgfile=$(readlink -f $2)
+stordir=$(readlink -f $3)
+tempdir=/tmp/mysqlbak_$$
+currdat=$(date +%Y%m%d)
+archive=$(hostname -s)
+tarname=mysqlbak_${archive}_${currdat}
+
+case $(uname) in
+       FreeBSD) statres=$(stat -f %Sp/%Su ${passfile});;
+       Linux) statres=$(stat -c %A/%U ${passfile});;
+       *) echo Unknown OS.; exit 1;;
+esac
+
+if [ "${statres}" != "-r--------/$(whoami)" ]
+then
+       echo "Password file must have 400 permissions and must be owned by you! (And it must exist, by the way.)"
+       exit 1
+fi
+dbpass=$(cat ${passfile})
+
+umask 027
+mkdir ${tempdir}
+cd ${tempdir}
+cat ${cfgfile} | while read db
+do
+       sqlfile=mysqlbak_${db}_${currdat}.sql
+       if ! mysqldump --user root --password=${dbpass} --databases ${db} > ${sqlfile};
+       then
+               echo "Failed to dump ${db} to ${sqlfile}."
+               rm ${sqlfile}
+       fi
+done
+
+if tar cvf ${tarname}.tar *.sql;
+then
+       rm *.sql
+       bzip2 --best *.tar
+       mv ${tarname}.tar.bz2 ${stordir}
+
+       cd ${stordir}
+       rmdir ${tempdir}
+
+       shift 3
+       for target in "$@"
+       do
+               scp ${tarname}.tar.bz2 ${target}
+       done
+else
+       echo "Failed to create archive: ${tarname}."
+       exit 1
+fi
diff --git a/mysql/mysqlbak_check.sh b/mysql/mysqlbak_check.sh
new file mode 100755 (executable)
index 0000000..ca63a58
--- /dev/null
@@ -0,0 +1,57 @@
+#!/bin/sh
+# By MegaBrutal
+#
+# Changelog:
+# 2014-09-13: Changed bzip2 test to tar tvf
+# 2014-01-03: Last known modification before changelog
+
+if [ "$#" -eq "0" ]
+then
+       echo "Usage: $0 list of backup directories"
+       echo "E.g.: $0 vps1 vps2 vps3"
+       exit 1
+fi
+
+CURRDAT=$(date +%Y%m%d)
+
+echo SYSTEM INFO:
+uname -a
+echo
+echo SYSTEM UPTIME:
+uptime
+echo
+echo
+echo
+
+while [ "$1" ]
+do
+       BAKDIR=$1
+       echo CHECKING ${BAKDIR}:
+       echo
+       echo "Checking for today's backup:"
+       if ls -l ${BAKDIR}/*${CURRDAT}*
+       then
+               echo
+               echo "Checking contents & consistency:"
+               if tar tvf ${BAKDIR}/*${CURRDAT}* 2>&1
+               then
+                       echo
+                       echo 'Today'\''s backup has successfully arrived.'
+               else
+                       echo 'TODAY'\''S BACKUP IS PRESENT BUT DAMAGED! MOST LIKELY IT IS ONLY PARTIALLY TRANSFERRED!'
+                       echo 'PLEASE RETRANSFER!'
+               fi
+       else
+               echo 'TODAY'\''S BACKUP IS NOT PRESENT!!!'
+               echo 'PROBABLY IT HASN'\''T BEEN TRANSFERRED DUE TO NETWORK PROBLEMS OR IT HAS NEVER BEEN MADE AT ALL!'
+               echo 'PLEASE CHECK SOURCE LOCATION!'
+       fi
+       echo
+       echo
+       echo "Other backup files present (most recent at top):"
+       ls -lt ${BAKDIR}/*
+       echo
+       echo
+       echo
+       shift
+done
diff --git a/smf/check_smf_pending_users.sh b/smf/check_smf_pending_users.sh
new file mode 100755 (executable)
index 0000000..d5c67df
--- /dev/null
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+if [ $# -lt 4 ]
+then
+       echo "Usage: $0 <SMF database> <table prefix> <DB user> <password file>"
+       exit
+fi
+
+dbname=$1
+dbpref=$2
+dbuser=$3
+dbpass=$4
+
+if [ "$(stat -c %A/%U ${dbpass})" != "-r--------/$(whoami)" ]
+then
+       echo "Password file must have 400 permissions and must be owned by you! (And it must exist, by the way.)"
+       exit
+fi
+
+mysqlargs="--user=${dbuser} --password=$(cat ${dbpass}) --database=${dbname} --default-character-set=utf8 --table"
+
+echo SYSTEM INFO:
+uname -a
+echo
+echo SYSTEM UPTIME:
+uptime
+echo
+echo MYSQL VERSION:
+/usr/sbin/mysqld --version
+echo
+echo DATABASE NAME:
+echo ${dbname}
+echo
+echo
+echo Users awaiting approval:
+echo
+mysql ${mysqlargs} --execute="SELECT id_member, member_name, email_address, FROM_UNIXTIME(date_registered) FROM ${dbpref}_members WHERE is_activated=3 ORDER BY date_registered DESC;"
+echo
+echo
+echo Approved users with zero posts:
+echo
+mysql ${mysqlargs} --execute="SELECT id_member, member_name, email_address, FROM_UNIXTIME(date_registered), FROM_UNIXTIME(last_login) FROM ${dbpref}_members WHERE is_activated=1 AND posts=0 ORDER BY date_registered"
diff --git a/smf/mail_user_profile.sh b/smf/mail_user_profile.sh
new file mode 100644 (file)
index 0000000..404b5e3
--- /dev/null
@@ -0,0 +1,4 @@
+# PLACEHOLDER FILE!
+# This script is not yet ready for publication, as it contains environment-specific and/or hard-coded sensitive data.
+# This file is here to annoy myself to make an update.
+#      ~ MegaBrutal
diff --git a/smf/smf_fetch_user_profile.sh b/smf/smf_fetch_user_profile.sh
new file mode 100755 (executable)
index 0000000..56852cc
--- /dev/null
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+if [ $# -lt 5 ]
+then
+       echo "Usage: $0 <SMF database> <table prefix> <DB user> <password file> <SMF member ID>"
+       exit
+fi
+
+dbname=$1
+dbpref=$2
+dbuser=$3
+dbpass=$4
+smfidmember=$5
+
+if [ "$(stat -c %A/%U ${dbpass})" != "-r--------/$(whoami)" ]
+then
+       echo "Password file must have 400 permissions and must be owned by you! (And it must exist, by the way.)"
+       exit
+fi
+
+mysqlargs="--user=${dbuser} --password=$(cat ${dbpass}) --database=${dbname} --default-character-set=utf8"
+
+echo SYSTEM INFO:
+uname -a
+echo
+echo SYSTEM UPTIME:
+uptime
+echo
+echo MYSQL VERSION:
+/usr/sbin/mysqld --version
+echo
+echo DATABASE NAME:
+echo ${dbname}
+echo
+echo SMF USER:
+mysql ${mysqlargs} --batch --raw --skip-column-names --execute="SELECT id_member, member_name FROM ${dbpref}_members WHERE id_member = $smfidmember" | sed 's+\t+ / +'
+echo
+echo
+echo User profile:
+echo
+mysql ${mysqlargs} --execute="SELECT * FROM ${dbpref}_members WHERE id_member = $smfidmember\G"
+echo
+echo
+echo Custom profile settings:
+echo
+mysql ${mysqlargs} --execute="SELECT * FROM ${dbpref}_themes WHERE id_member = $smfidmember\G"