nothing is impossible!!!!

nothing is impossible!!!!

Wednesday, August 26, 2009

How to setup rsync

If you want to run rsync as a daemon make sure following thing.
- rsync is not hashed in /etc/services

- I have created following script to start rsync daemon which uses /etc/rsyncd.conf file

######### Creating start/stop script ..... /etc/init.d/rc.d/rsyncd

# Rsyncd This shell script takes care of starting and stopping the rsync daemon
# description: Rsync is an awesome replication tool.

# Source function library.
. /etc/rc.d/init.d/functions

[ -f /usr/bin/rsync ] || exit 0

case "$1" in
action "Starting rsyncd: " /usr/bin/rsync --daemon
action "Stopping rsyncd: " killall rsync
echo "Usage: rsyncd {start|stop}"
exit 1
exit 0


######### Create /etc/rsyncd.conf file

### Rsync Configurations ###
uid = nobody
gid = nobody
use chroot = no
max connections = 10
syslog facility = local5
pid file = /var/run/
motd file = /etc/rsyncd.motd
lock file = /var/run/rsync.lock

path = /backup/
auth users = backup
comment = Main backup directory.
#### secrets file = /etc/rsyncd.secrets

We should take care of trailing "/" while specifying the source directory for data copying.
for example,

rsync -avz -e ssh remoteuser@remotehost:/remoterdir/data/for/copy/ /local/data/dir

Above example means that /local/data/dir must be available to to receive data from /remoterdir/data/for/copy/, otherwise rsync will simply download all the files into the path given as destination.

rsync -avz -e ssh remoteuser@remotehost:/remoterdir/data/for/copy /local/data/dir
in this case "copy" directory will be created first under /local/data/dir directory and data will be populated from remote host.

I have created script to copy data remotely.

# Script to copy data on remote machine.


$RSYNC -avz -e $RSSH /backup/daily/ $RUSER@$RHOST:$RDATABASE/MySQL/
$RSYNC -avz -e $RSHH /var/www/html/ $RUSER@$RHOST:$RDIR

Please generate password less keys to copy data remotely without interruption. Use "ssh-keygen"

Monday, August 24, 2009

Postgresql backup and restore.

First method using pg_dump and second one is file system level backup.

Dump level Backup:
pg_dump dbname > outfile

Options available with pg_dump,
-h hostname. Default is localhost or whatever is set in PGHOST variable.
-p which port. PGPORT env.
-U username. default is logged in user name. PGUSER env.
outfile - name of the target file

pg_dump does not block other operations on the database while it is working. (Exceptions are those operations that need to operate with an exclusive lock, such as VACUUM FULL.)

psql dbname < infile
infile - infile is what you used as outfile for the pg_dump command.

It is suggested to run analyze on each db to obtain the useful statistics. Run,
vacuumdb -a -z to VACUUM ANALYZE all databases;

pg_dump and psql can also use to dump a database directly from one server to another;
for example:
pg_dump -h host1 dbname | psql -h host2 dbname

2. File system level backup
tar -cf backup.tar /usr/local/pgsql/data
- Servers must be shutdown before taking backup.
- To restore database, we have to restore full database, can not do partial restore of tables or etc.

Wednesday, August 12, 2009

Open GUI application via ssh

ssh -p 2222 -l nilesh -X -v {}

-p 2222 In case your server runs a non-standard TCP port.
(If yours runs on the default port (TCP port 22), there is no need to add this option.)

-l nilesh is only required if you do not have matching usernames on remote host.

-X allows X forwarding. Use -x can be used to disable X11 forwarding

-v is verbose. This lets you watch what is going on.

Run your application once it is done.
I was about to run virt-manager GUI application, which ran successfully :)

Virtualization: Xen Installation

How Xen works?
Xen hypervisor is run on top of the hardware which is the virtual machine monitor. Guest operating systems are run on top of this hypervisor, thus all guest operating systems are secondary to the hardware and contacts the hardware through the hypervisor. The first thing for grub would be to load the hypervisor. Look at the /boot/grub/grub.conf which loads the xen.gz-2.6.18-128.4.1.el5 which is the hypervisor.

Hypervisor loads the Dom-0 kernel and initrd image and starts the main system. Dom-0 itself is a guest operating system with additional privileges to manage other guest operating systems and is started with system start up.

Following rpms should be installed for Xen virtualization,
- kernel-xen ---> Dom-0 and Dom-U kernels.
- xen ----------> Xen hypervisor and other management tools.
- libvirt ------> Libraries required to manage domains which is used as a backend for virtmanager.
- virt-manager ----> GUI interface to manage guests

Once installation of above RPM's are done, System should be rebooted using the new XEN kernel.

Tuesday, August 11, 2009

Hidden ports on Linux.

A nice blog post about the hidden ports on linux.