Database backup/restore in Postgres

To take Postgres database backup you can use below command.

Backup:  $ pg_dump -U {user-name} {source_db} -f {dumpfilename.sql}

For restore procedure use below:

Restore: $ psql -U {user-name} -d {desintation_db}-f {dumpfilename.sql}

To backup all databases use below command:

pg_dumpall > all.sql

To backup a specific postgres table
$ pg_dump --table tablename -U username databasename -f tablebackupfule.sql


To restore postgres database use below command

$ psql -U username -d databasename -f mydb.sql

To restore all databases

psql -f alldb.sql

To restore specific table:

psql -f tablebackupfile.sql databasename

Thanks

Sample IPTABLES rules in Linux

Here I'm going to set Iptables in linux to allow traffic from perticular source to perticular destination on perticular port. Other incoming/outgoing traffic will be blocked.

rules are given in script file.

#!/bin/sh
# My system IP/set ip address of server
SERVER_IP="192.168.100.233"
# Flushing all rules
iptables -F
iptables -X
# Setting default filter policy
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
# Allow unlimited traffic on loopback
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT


# Allow incoming ssh only
iptables -A INPUT -p tcp -s 192.168.100.32 -d $SERVER_IP --sport 513:65535 --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp -s $SERVER_IP -d 0/0 --sport 22 --dport 513:65535 -m state --state ESTABLISHED -j ACCEPT


# Allow incoming DB2 only
iptables -A INPUT -p tcp -s 192.168.100.231 -d $SERVER_IP --sport 513:65535 --dport 50000 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp -s $SERVER_IP -d 0/0 --sport 50000 --dport 513:65535 -m state --state ESTABLISHED -j ACCEPT


# Allow incoming NAGIOS only
iptables -A INPUT -p tcp -s 192.168.100.253 -d $SERVER_IP --sport 513:65535 --dport 5666 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp -s $SERVER_IP -d 0/0 --sport 5666 --dport 513:65535 -m state --state ESTABLISHED -j ACCEPT


# Allow incoming ICMP only
iptables -A INPUT -p tcp -s 192.168.100.253 -d $SERVER_IP --sport 513:65535 --dport 5666 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp -s $SERVER_IP -d 0/0 --sport 5666 --dport 513:65535 -m state --state ESTABLISHED -j ACCEPT


# make sure nothing comes or goes out of this box
iptables -A INPUT -j DROP
iptables -A OUTPUT -j DROP


The above rules are self explanatory. Lets discuss if you have any query.

Thank you.

Installing java in Linux

Downloading

Download the latest version of JDK from http://www.java.sun.com. I have downloaded jdk-1_5_0_01-linux-i586.bin for this tutorial.
Installing
Change to the directory where you downloaded the JDK ( I downloaded it in my home directory /home/alpesh) and make the self-extracting binary executable:
chmod +x jdk-1_5_0_01-linux-i586.binRun the self-extracting binary, this will display the License agreement text and will ask you to accept the agreement:
./jdk-1_5_0_01-linux-i586.bin
Above command should create a directory called jdk1.5.0_01 in the /home/alpesh directory. Move the JDK directory to /opt . Here is the command used:
mv jdk1.5.0_01 /opt
Set the JAVA_HOME environment variable, by modifying /etc/profile so it includes the following:
JAVA_HOME="/opt/jdk1.5.0_01"
export JAVA_HOME


save /etc/profile file. Then run following command to take into effect.
source /etc/profile
Check to make sure JAVA_HOME is defined correctly using the command below. You should see the path to your Java JDK.
echo $JAVA_HOME
Output should be
/opt/jdk1.5.0_01
Now need to set out new Java as default thorugh alternative utility. First we will install alternative java then we will configure it make it as default java.
To install java using alternative command:
alternatives --install /usr/bin/java java /opt/jdk1.5.0_01/bin/java 2
Now need to configure it to make it as default Java location:

alternatives -config java

Above command will give below output. There we will have to select latest java location.
[root@alpeshpc opt]# alternatives --config java

There are 3 programs which provide 'java'.

Selection Command
-----------------------------------------------
* 1 /usr/lib/jvm/jre-1.4.2-gcj/bin/java
2 /opt/jdk1.5.0_01/bin/java

Give there number 2, then press enter.

Thats it.

Now you can check Java installation using java –version command.
Now you can check Java installation using java –version command.
  • You may come across issue, even if java installed but your browser will give warning that java is not installed. So you will need to follow below steps to make java applet work in browser.
Note: You may have different java version, so change java version accordingly in below commands.

## Java Browser (Mozilla) Plugin 32-bit ## 
alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so /usr/java/jdk1.6.0_33/jre/lib/i386/libnpjp2.so 20000   

## Java Browser (Mozilla) Plugin 64-bit ## 
alternatives --install /usr/lib64/mozilla/plugins/libjavaplugin.so libjavaplugin.so.x86_64 /usr/java/jdk1.6.0_33/jre/lib/amd64/libnpjp2.so 20000

Cisco Anyconnect VPN client in Linux

Before we start installation of Cisco anyconnect VPN client, I assume that Certificates has been installed in browser. If so, then follow given steps.

# downloaded the latest Linux Anyconnect client from http://www.cisco.com
tar -xvzf anyconnect-linux-2.3.0185-k9.tar.gz
cd ciscovpn/
sudo ./vpn_install.sh

# Downloaded latest firefox from http://www.mozilla.com/en-US/firefox/ and extract into /usr/local directory only.
sudo tar -xvjf firefox-3.0.5.tar.bz2 -C /usr/local

After the give below command to create soft link of library files.

for lib in libnssutil3.so libplc4.so libplds4.so libnspr4.so libsqlite3.so libnssdbm3.so libfreebl3.so ; do sudo ln -s /usr/local/firefox/$lib /opt/cisco/vpn/lib/$lib ; done

Once above mentioned steps followed, start Cisco Anyconnect VPN client and check if it is working or not. If you get Certificate errors then try using above mentioned commands using root user.