Tuesday, October 11, 2011

Exclude Directories or Files with Tar

I often do backups of my public_html but since I don't need folders like phpMyAdmin and logs, I found an easy way to do that in order to reduce backup size.The command to do this is:
tar -zcvf backup.tar.gz public_html/ --exclude "public_html/phpMyAdmin" --exclude "public_html/logs"


I am outside the public_html directory while doing this.For a more general case, it would be:
tar -zcvf filename.tar.gz directory_to_backup --exclude "directory_to_exclude"


This way, I save time and space.Hope this will be useful.
Remember that individual files can be too excluded by replacing directory with filename.

Catching all emails for a domain with Postfix(Catch all Emails)


We have to add a wildcard entry in /etc/postfix/virtual or any virtual mapping files.For simplicity we use /etc/postfix/virtual  file and append this:
@example.com  admin
And we have to do this to map that:
postmap /etc/postfix/virtual
And add this line if it does’t exist in /etc/postfix/main.cf:
virtual_alias_maps = hash:/etc/postfix/virtual
Finally,
/etc/init.d/postfix restart

This way every email sent to anything@example.com will be redirected to admin@example.com

Changing User Login Shell On Linux


There are many kinds of shells available.I prefer bash shell which is default on Debian Systems.
To see available shells,do:
cat /etc/shells
To change the shell for a user,we have to edit /etc/passwd file and replace the line /bin/shellname to  your preferred shell.
For example, replace /bin/sh to /bin/bash for user to which it is being done.

Sunday, October 9, 2011

Creating a backup tar archive

With tar, it is easy to backup whole directory including its permissions.To do this on a directory called 'web', we would type:
tar -pczf web.tar.gz web/
Thus, a tar archive is created and you can restore it with:
tar -pxzf web.tar.gz