Skip to content

Instantly share code, notes, and snippets.

View blu3Alien's full-sized avatar

Christopher Rabe blu3Alien

View GitHub Profile
@blu3Alien
blu3Alien / server_backup.sh
Created January 25, 2013 12:11
Shell script to store a compressed backup of vital server files in the users home directory. Note: Care should be taken when using this. Consider changing the backup location.
#!/bin/sh
date=`date -I`
log_date=`date -u`
# Compress and backup /etc directory
tar -cvf ~/backup/etc-$date.tar /etc
echo "[$log_date]: Backing up /etc directory. (etc-$date.tar)" >> ~/backup/logs/_backup.txt
# Compress and backup /home directory
tar -cvzf ~/backup/home-$date.tar /home
@blu3Alien
blu3Alien / sql_restore.sh
Created January 25, 2013 12:04
Shell script to restore a supplied compressed mySQL backup. Note: update username and password before using.
#!/bin/sh
doContinue=n
echo -n "Do you really want to continue? [y/n] "
read doContinue
if [ "$doContinue" != "y" ]; then
echo "Quitting..."
exit
fi
@blu3Alien
blu3Alien / sql_backup.sh
Created January 25, 2013 12:01
Shell script to store a compressed backup of all mySQL databases in the users home directory. Note: modify mySQL username and password before using.
#!/bin/sh
date=`date -I`
log_date=`date -u`
# Dump and compress all mySQL databases to remote external drive
mysqldump --user=[username] --password=[password] --all-databases | gzip > ~/backup/sql_backup-$date.sql.gz
echo "[$log_date]: Backing up all MySQL databases. (sql_backup-$date.sql.gz)" >> ~/backup/logs/_backup.txt
# Only keep mySQL backups for 14 days
find ~/backup/ -name "*gz" -mtime +14 -exec rm{} \;
@blu3Alien
blu3Alien / pingscan.sh
Created January 21, 2013 13:16
Shell script to scan a range of IP addresses. USAGE: ./pingscan 192.168.1.
#!/bin/sh
: ${1?"Usage: $0 ip subnet to scan. eg '192.168.1.'"}
subnet=$1
for addr in `seq 0 1 255 `; do
# ( echo $subnet$addr)
( ping -c 3 -t 5 $subnet$addr > /dev/null && echo $subnet$addr is Alive ) &
done