Wednesday, February 9, 2011

rsync command primer

rsync is used to perform the backup operation in UNIX / Linux.
rsync utility is used to synchronize the files and directories from one location to another in an effective way. Backup location could be on local server or on remote server.

Important features of rsync

  • Speed: First time, rsync replicates the whole content between the source and destination directories. Next time, rsync transfers only the changed blocks or bytes to the destination location, which makes the transfer really fast.
  • Security: rsync allows encryption of data using ssh protocol during transfer.
  • Less Bandwidth: rsync uses compression and decompression of data block by block at the sending and receiving end respectively. So the bandwidth used by rsync will be always less compared to other file transfer protocols.
  • Privileges: No special privileges are required to install and execute rsync

Syntax

$ rsync options source destination 
 
$ rsync -zvr /var/opt/installation/inventory/ /root/temp  
In the above rsync example:
  • -z is to enable compression
  • -v verbose
  • -r indicates recursive

Example 2. Preserve timestamps during Sync using rsync -a

$ rsync -azv /var/opt/installation/inventory/ /root/temp/ 

Example 3. Synchronize Only One File

$ rsync -v /var/lib/rpm/Pubkeys /root/temp/ 

Example 4. Synchronize Files From Local to Remote

$ rsync -avz /root/temp/ thegeekstuff@192.168.200.10:/home/thegeekstuff/temp/ 
 
$ rsync -avz thegeekstuff@192.168.200.10:/var/lib/rpm /root/temp 

 Example 7. Do Not Overwrite the Modified Files at the Destination

In a typical sync situation, if a file is modified at the destination, we might not want to overwrite the file with the old file from the source. Use rsync -u option to do exactly that.
 
$rsync -avzu thegeekstuff@192.168.200.10:/var/lib/rpm /root/temp 
 

Example 8. Synchronize only the Directory Tree Structure (not the files)

Use rsync -d option to synchronize only directory tree from source to the destination. The below example, synchronize only directory tree in recursive manner, not the files in the directories.
 
rsync -v -d thegeekstuff@192.168.200.10:/var/lib/ .

 

dd command primer

Example 1. Backup Entire Harddisk

# dd if=/dev/sda of=/dev/sdb
 
# dd if=/dev/sda of=/dev/sdb conv=noerror,sync
  • “if” represents inputfile, and “of” represents output file. So the exact copy of /dev/sda will be available in /dev/sdb.
  • If there are any errors, the above command will fail. If you give the parameter “conv=noerror” then it will continue to copy if there are read errors.
  • Input file and output file should be mentioned very carefully, if you mention source device in the target and vice versa, you might loss all your data.

Example 2. Create an Image of a Hard Disk

# dd if=/dev/hda of=~/hdadisk.img
 

Example 3. Restore using Hard Disk Image


# dd if=hdadisk.img of=/dev/hdb
 

 Example 6. CDROM Backup

dd if=/dev/cdrom of=tgsservice.iso bs=2048
 

 

raw device verify

Raw devices for OCR(or any voting, ASM etc), which are shared across RAC cluster nodes.  To confirm if they are same device across all nodes aka all nodes are pointing to same/similar raw device

Check OCR raw devices
./ocrcheck

dd if=/dev/emcpowera1 bs=1024000 count=100 |od -c > /tmp/dd_node1.txt

Run similar commands on all nodes on RAC cluster.

File Size and content should match on all nodes for /tmp/dd_node1.txt.

ASM Disk commands

Status
/etc/init.d/oracleasm status

To list disks
/etc/init.d/oracleasm listdisks

Check Specific Disk
/etc/init.d/oracleasm querydisk -d ASM1D0022

ASM  configuration  file
/etc/sysconfig/oracleasm

Find physical disk associated with ASM Disk

#/etc/init.d/oracleasm querydisk -d ASM1D0001
Disk "ASM1D0001" is a valid ASM disk on device [120, 129]

#ls -ltr /dev |grep 129



 brw-r-----  1 root   disk  70,   129 Jan 30 17:31 sdda1
brw-r-----  1 root   disk  67,   129 Jan 30 17:31 sdbe1
brw-r-----  1 root   disk  66,   129 Jan 30 17:31 sdao1
brw-r-----  1 root   disk   8,   129 Jan 30 17:32 sdi1
brw-r-----  1 root   disk  68,   129 Jan 30 17:32 sdbu1
brw-r-----  1 root   disk  65,   129 Jan 30 17:32 sdy1
brw-r-----  1 root   disk  69,   129 Jan 30 17:32 sdck1
brw-rw----  1 oracle dba  120,   129 Jan 30 17:32 emcpoweri1
crw-------  1 vcsa   tty    7,   129 Jan 30 17:34 vcsa1

Display EMC power path info

#sudo ./powermt display dev=/dev/emcpoweri1

# Below will display all EMC power paths
#sudo ./powermt display dev=all > /tmp/mnt_info.lis