Thursday, August 9, 2012

Copying Files and Directories commands for DBAs:

Copying Files  and Directories commands for DBAs:
 Hi DBAs,
         Many of our tasks deals with copying of Data within same and Different server from Windows to Linux(Unix Based) OS or from any Unix based Operating system
to Other Unix based Operating system.We can use different commands and tools for doing it.Below I'm sharing my experience.
       
1)tar:tar stands for translate archive.It is most favourite commands for Apps DBAs when performing clonning and refreshing of environment,we use this command for copying huge size directories from one environment to other environment,tar when combined with gzip is the best combination.tar is the most powerful command.

2)scp:scp stands for secure copy.It is the fastest command for copying,again handy tool for DBAs and Apps DBAs.It is use to copy files and directories from one server to another server.

3)gzip and gunzip:gzip is use for compressing files on Unix-based system and gunzip is use for uncompressing the files on Unix-based systems i.e Solaris,Linux,IBM-AIX,HP-UX.
Again very useful command for DBA.

Eg 1:Let's say I want to tar and zip a directory 'bin' and copy it to target server

On Source System:
=================

Tarring and zipping:
===================

tar -cvf - bin | gzip >bin.tar.gz


On Target System:
=================

Copying to Target system:
==========================

scp -rp oracle@testpapp01cdp.comp.com:/product/app/TESTAPPSDB/apps/apps_st/appl/xxtwc/12.0.0/bin.tar.gz .

passwd:

Extracting and Untarring:
=========================

gunzip -c bin.tar.gz|tar -xvf -
 
Eg 2:

For Compressing:
=================

Let's say you are currently in /product/obiee Directoy and want to compress and zip the OracleBIData Directory,than it can be done as follows:

tar -cvf  /product/obiee/OracleBIData.tar OracleBIData/


>ls -altr
total 987816
drwxr-x---   9 obiee    psapps      1024 Jul  6  2010 OracleBIData
drwxr-xr-x   4 obiee    psapps        96 Jul  9  2010 java
drwxr-x---  20 obiee    psapps      1024 Dec  9  2010 OracleBI
drwxr-xr-x  16 applmgr  oinstall    1024 May 12  2011 ..
drwxrwxrwx   5 obiee    oinstall    1024 Aug  8 21:05 .
-rw-r--r--   1 obidev2  psapps   505448448 Aug  8 21:17 OracleBIData.tar


For Zipping the Directory:
-----------------------------------------------------

$gzip OracleBIData.tar


>ls -altr
total 78256
drwxr-x---   9 obiee    psapps      1024 Jul  6  2010 OracleBIData
drwxr-xr-x   4 obiee    psapps        96 Jul  9  2010 java
drwxr-x---  20 obiee    psapps      1024 Dec  9  2010 OracleBI
drwxr-xr-x  16 applmgr  oinstall    1024 May 12  2011 ..
-rw-r--r--   1 obidev2  psapps   40054038 Aug  8 21:17 OracleBIData.tar.gz


Eg 3:


For Unzipping the Directory:
------------------------------------

$gunzip OracleBIData.tar.gz


For untarring/extracting the Directory:
-------------------------------------------

$tar -xvf OracleBIData.tar


Note:
gzip=>compression
c=create
v=verbose

tar with gzip are the best method to take the backup of directory,since we can do it very fast and it saves the Disk space efficiently.

Note:tar command options are operating system dependent,so please check with man command command for using various options.


4)rsync:rsync is a great tool for backing up and restoring files,from source system to target system.It is Useful tool for DBAs.It is very important to remember this command works on linux and Doesn't work on Solaris Operating system as rsync doesn't have manual entry on it.

Eg 4:Copy all directories and file structure with all the ownership,permissions and symbolic links.


On Target System:
=================

rsync -arv oracle@testpapp01cdp.comp.com:/tmp/rafi/bin /tmp/rafi/backup_bin

(/tmp/rafi=>current working directory on Target Server)


5)sftp:sftp stands for secure file transfer protocol.some times if scp ports are disabled due to security reason than you can use sftp.It is very much secure way
of copying files and directories from source to target Server.This is very useful for DBAs and Apps DBAs.

Eg 5:Copying files from one server to other server

Using sftp for copying from qb to prod:
------------------------------------------

On Target System:
=================

oracle@[testpapp01cdp]-> sftp oracle@testqapp02cdp.comp.com:/tmp/rafi
Connecting to testqapp02cdp.comp.com...
Password:
Changing to: /tmp/rafi
sftp> ls
sftp> get lookup_xxtwc_perf_level_planned_perc.ldt
Fetching /tmp/rafi/lookup_xxtwc_perf_level_planned_perc.ldt to lookup_xxtwc_perf_level_planned_perc.ldt

6)winscp:winscp is GUI(Graphical user interface) based tool for copying files from windows to Linux(Unix environment) and vice-versa.I like this tool very much,since it is very much user friendly.But,for copying large amount of data it takes using this tool.In this tool you can save the machine name and login with privilege user and copy the files.

7)ftp:ftp stands for  file transfer protocol and use for copying files from windows to linux(Unix environment) and vice-versa.This is fast method of copying files.
 2mb of data can be copied in less than 5 minutes.

Eg 7:

On Target System(Windows):
===========================

Go to the target folder in windows.

C:\Documents and Settings\rafiuddin_alvi>cd D:\TEST

C:\Documents and Settings\rafiuddin_alvi>d:

D:\TEST>ftp testdapp01cdc.comp.com
Connected to testdapp01cdc.comp.com.
220 testdapp01cdc.comp.com FTP server ready.
User (testdapp01cdc.comp.com:(none)): oracle
331 Password required for oracle.
Password:
230 User oracle logged in.
ftp> help
Commands may be abbreviated.  Commands are:

!               delete          literal         prompt          send
?               debug           ls              put             status
append          dir             mdelete         pwd             trace
ascii           disconnect      mdir            quit            type
bell            get             mget            quote           user
binary          glob            mkdir           recv            verbose
bye             hash            mls             remotehelp
cd              help            mput            rename
close           lcd             open            rmdir
ftp> cd /tmp/rafi
250 CWD command successful.
ftp> dir
200 PORT command successful.
150 Opening ASCII mode data connection for /bin/ls.
total 4640
-rwxrwxrwx   1 oracle  twcother 2272275 Aug  6 03:18 cn_reports.rpd
-rwxrwxrwx   1 oracle  twcother    8115 Jul  7 19:07 DisputeSrchPG.xml
-rwxrwxrwx   1 appldev2 oinstall     916 Jul 25 04:38 L6958530.log
-rwxrwxrwx   1 appldev2 oinstall     880 Aug  6 08:06 L6960409.log
-rwxr-xr-x   1 oracle  twcother      23 Aug  8 20:11 test1.sh
-rwxrwxrwx   1 appldev2 oinstall   22889 Jul 25 04:38 XX_QUINTILE_BATCH.ldt
-rwxrwxrwx   1 oracle  twcother    1802 Jul  5 06:48 XXTaskPerzSumCO.class
-rwxrwxrwx   1 oracle  twcother    1934 Jul  7 19:07 XXTaskSummaryCO.class
-rwxrwxrwx   1 appldev2 oinstall   20235 Aug  6 08:06 XXTWC_REPORT_METRIC_VAL
.ldt
226 Transfer complete.
ftp: 672 bytes received in 0.08Seconds 8.62Kbytes/sec.
ftp> get test1.sh
200 PORT command successful.
150 Opening ASCII mode data connection for test1.sh (23 bytes).
226 Transfer complete.
ftp: 24 bytes received in 0.00Seconds 24000.00Kbytes/sec.

ftp> get cn_reports.rpd
200 PORT command successful.
150 Opening ASCII mode data connection for cn_reports.rpd (2272275 bytes).
226 Transfer complete.
ftp: 2284457 bytes received in 113.08Seconds 20.20Kbytes/sec.

     To exit ftp:
  
ftp> bye
221-You have transferred 2284481 bytes in 2 files.
221-Total traffic for this session was 2285843 bytes in 3 transfers.
221-Thank you for using the FTP service on testdapp01cdc.comp.com.
221 Goodbye.

b)Putting files from source(Windows) to Target(Linux):

ftp> mput my_docs.txt
mput my_docs.txt? y
200 PORT command successful.
150 Opening ASCII mode data connection for my_docs.txt.
226 Transfer complete.
ftp> dir
200 PORT command successful.
150 Opening ASCII mode data connection for /bin/ls.
total 4640
-rwxrwxrwx   1 oracle  twcother 2272275 Aug  6 03:18 cn_reports.rpd
-rwxrwxrwx   1 oracle  twcother    8115 Jul  7 19:07 DisputeSrchPG.xml
-rwxrwxrwx   1 appldev2 oinstall     916 Jul 25 04:38 L6958530.log
-rwxrwxrwx   1 appldev2 oinstall     880 Aug  6 08:06 L6960409.log
-rw-r--r--   1 oracle  twcother       0 Aug  8 20:48 my_docs.txt
-rwxr-xr-x   1 oracle  twcother      23 Aug  8 20:11 test1.sh

8)cp:cp is the most basic command in linux(Unix environment) for copying files within same directory or directories on Same server.

Eg 8:To copy test1.sh to Target location /tmp/rafi,we can use below command.

testdapp01cdc(/export/home/oracle) >cp test1.sh /tmp/rafi

testdapp01cdc(/tmp/rafi) >ls -altr *test*
-rwxr-xr-x   1 oracle  twcother      23 Aug  8 20:11 test1.sh



Hope it helps....

Enjoy DBA learning...


Best regards,

Rafi.







1 comment:

  1. thanks for all your info
    But I work in solaris 11 and I found rsync command .
    thanks

    ReplyDelete