pirmdiena, 2011. gada 9. maijs

PuTTY + vim + paste

This is annoying when you can't click mouse in vim to paste some text.
Add following lines to .vimrc to fix that:
if has('mouse')
      set mouse-=a
endif

trešdiena, 2011. gada 4. maijs

iptables in slackware

Basic firewall configuration 
Drop INPUT, FORWARD
# iptables -P INPUT DROP
# iptables -P FORWARD DROP


Accept establised
# iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

Accept loopback
# iptables -A INPUT -s 127.0.0.0/8 -d 127.0.0.0/8 -i lo -j ACCEPT

Accept SSH
# iptables -A INPUT -p tcp --dport 22 -i eth0 -j ACCEPT

Accept ICMP
# iptables -A INPUT -p icmp -j ACCEPT

View
# iptables -L

With line numbers
# iptables -L --line-numbers

Save
# iptables-save > /root/fw.conf

To enable on next boot, add line to /etc/rc.d/rc.local
iptables-restore < /root/fw.conf

otrdiena, 2011. gada 12. aprīlis

Incremental htdir backup script.sh

#! /bin/sh
cd /backup

TODAY=`date`
FILENAME=`date +%d%b%Y`-inc-htdir.tar.gz.sec


# Check last backup date
if [ -f lastbackup ]; then
LAST=`cat lastbackup`
else
LAST=$TODAY
fi


# Create .tar.gz
tar -czf htdir.tar.gz --after-date="$LAST" /var/www/htdocs

# Encode with SSL
openssl des -in htdir.tar.gz -out $FILENAME -pass pass:secpasswd

# Send to remote backup machine
scp $FILENAME backup@10.0.2.251:/backup/data/www/htdir

# Cleanup n' shit
echo `md5sum $FILENAME` >> md5sum.log
rm htdir.tar.gz $FILENAME
echo $TODAY > lastbackup

svētdiena, 2011. gada 30. janvāris

Customize xterm

Create or edit ~/.Xdefaults

XTerm*background: black
XTerm*foreground: #CCCCCC
XTerm*highlightColor: red
XTerm*font: *-fixed-medium-r-*-14-*
XTerm*boldFont: *-fixed-medium-r-*-14-*
XTerm*geometry: 110x34+200+200

add to ~/.bashrc:
alias ls="ls --color=auto"
PS1='\u@\H:\w\$ '

ceturtdiena, 2011. gada 27. janvāris

Creating image with dd

*This does not work on the fly, so you need to boot from CD. 

Quick way with non-compressed image.

Create image from hda and save it on remote server:
# dd if=/dev/sda | ssh username@backupserver "dd of=/directory_of_backups_on_ssh_server/backupfile.iso"

Extract image to disk: 
# ssh user@hostname dd if=backupfile.iso | dd of=/dev/sda


Way with compressed image.

Create compressed image from sda on remote server:
# dd if=/dev/sda | gzip | ssh username@backupserver dd of=/directory_of_backups_on_ssh_server/backupfile.img.gz

Restore:
# ssh user@hostname dd if=backupfile.iso | gzip -d | dd of=/dev/sda


Clearing MBR with dd:
# dd if=/dev/zero of=/dev/hda bs=512 count=1 

otrdiena, 2011. gada 25. janvāris

System backup on-the-fly

Create:

# tar cvpzf backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/backup.tgz --exclude=/mnt --exclude=/sys /

For better compression, but it takes longer time:
# tar cvpjf backup.tar.bz2 --exclude=/proc --exclude=/lost+found --exclude=/backup.tar.bz2 --exclude=/mnt --exclude=/sys /

*At the end of the process you might get a message along the lines of 'tar: Error exit delayed from previous errors' or something, but in most cases you can just ignore that.

Restore:

# tar xvpfz backup.tgz -C /
# tar xvpfj backup.tar.bz2 -C /

Just make sure that, before you do anything else, you re-create the directories you excluded:
# mkdir proc
# mkdir lost+found
# mkdir mnt
# mkdir sys

etc...

pirmdiena, 2011. gada 17. janvāris

htdir backup script.sh

#!/bin/sh
# set chmod 700 to /backup for security reasons
cd /backup
FILENAME=`date +%d%b%Y`-htdir.tar.gz.sec

tar -cvf - /var/www/htdocs/ | gzip -c > htdir.tar.gz
openssl des -in htdir.tar.gz -out $FILENAME -pass pass:secpasswd
scp $FILENAME backup@backupsrv:/backup/srv1/htdir
echo `md5sum $FILENAME` >> md5sum.log
rm htdir.tar.gz $FILENAME