Archive for January, 2011

The dd utility can be successfully used to create a backup of a filesystem (in lack of more specialised backup utilites).

dd if=/dev/sdaX | gzip > /backup/sdaX.gz

where sdaX is the partition you want to backup, and the /backup folder is located on a different disk/partition than the one you’re backing up..

Only note that dd does not care whether a sector is used or not, it will copy it to the image file nonetheless. Zeroing out all free space before backup up is a good way to keep wasted backup space to a minimum (since the backup will be compressed)

Zero out free disk space

Author: lucian

This function comes in handy when you want to make a compressed sector-by-sector backup of the filesystem and you don’t want to include/waste space with the unused sector (which still have information on them)

Running

nice cat /dev/zero > zero.fill;sync;sleep 1;sync;rm -f zero.fill

before the actual backup will make sure all unused sectors contain zero (so they will not waste any space in the archives).

If you ever need to count the occurences of a character in all (or some) files, this next series of commands would come in handy:

for f in `ls`; do cat $f; done | awk ‘{ for ( i=1; i<=length; i++ ) arr[substr($0, i, 1)]++ }END{ for ( i in arr ) { print i, arr[i] } }’ | grep X

Replace X with the character in question. The command is all in one line. “ls” can be replaced with a more specific list (eg: “ls *.c“)

Merry New Year!

Author: lucian

Stop ACTA
own-cryoutcreations