Monday, April 25, 2011

Subversion Tutorial: 10 Most Used SVN Commands with Examples


SVN stands for Subversion.
Subversion is a free/open-source version control system. Subversion manages files and directories over time. A tree of files is placed into a central repository. The repository is much like an ordinary file server, except that it remembers every change ever made to your files and directories. This allows you to recover older versions of your code, or examine the history of how your code was changed.
This article explains some basic SVN commands with examples.

SVN Working Copy

SVN is a repository that holds all our versioned data, which is also called as SVN server. SVN client program which manages local reflections of portions of that versioned data which is called as working copy. SVN client can access its repository across networks. Multiple users can access the repository at the same time.

1. SVN Checkout – Create working copy

Checkout command is used to download sources from SVN repository to working copy. If you want to access files from the SVN server, checkout is the first operation you should perform.
SVN checkout creates the working copy, from where you can do edit, delete, or add contents. You can checkout a file, directory, trunk or whole project. To checkout you should know URL of the components you want to checkout.
Syntax:

$ svn checkout/co URL PATH
  • URL is the URL of the components to checkout
  • If PATH is omitted, the basename of the URL will be used as the destination. If multiple URLs are given each will be checked out into a subdirectory of PATH, with the name of the subdirectory being the basename of the URL.
The following example checks out the directory to the given target directory.
$ svn co https://www.thegeekstuff.com/project/branches/release/migration/data/cfg /home/sasikala/cfg/
A /home/sasikala/cfg/ftp_user.cfg
A /home/sasikala/cfg/inventory.cfg
A /home/sasikala/cfg/email_user.cfg
A /home/sasikala/cfg/svn-commands
Checked out revision 811.

$ ls /home/sasikala/cfg
. .. .svn email_user.cfg ftp_user.cfg inventory.cfg svn-commands
When you do a checkout, it creates hidden directory named .svn, which will have the repository details.

2. SVN Commit – Save changes to the repository

Whenever you do changes to the working copy, it will not reflect in SVN server. To make the changes permanent, you need to do SVN commit.
Syntax:

$ svn commit -m "log messages"
Explain why you are changing the file in the -m option.
For example, in my working copy, the file named “svn-commands” has the following content.
$ cat /home/sasikala/cfg/svn-commands
checkout
commit
add
delete
update
status

$ ls -l /home/sasikala/cfg/svn-commands
-rw-r--r-- 1 root root 41 Apr 16 11:15 svn-commands
I made a change in this file (for example, making this file empty).
$ ls -l svn-commands
-rw-r--r-- 1 root root 0 Apr 16 11:20 svn-commands
Now commit the file to make the changes permanent in the server.
$ svn commit -m "Making the file empty" svn-commands
Sending svn-commands
Transmitting file data .
Committed revision 813.
After this whenever you update your working copy or checkout, the changes will appear in the server.

3. SVN List – Lists directory entries

svn list is useful when you want to view the content of the SVN repository, without downloading a working copy.
Syntax:

$ svn list
The following example lists all the files available in the given URL in the repository without downloading a working copy. When you execute svn list command with –verbose option it displays the following information.
  • Revision number of the last commit
  • Author of the last commit
  • Size (in bytes)
  • Date and time of the last commit
$ svn list --verbose https://www.thegeekstuff.com/project/branches/release/migration/data/bin
16 sasikala 28361 Apr 16 21:11 README.txt
21 sasikala 0 Apr 18 12:22 INSTALL
22 sasikala Apr 18 10:17 src/

4. SVN Add – Add a new file to SVN repository

When you want to add a new file (or directory) to the repository you need to use SVN add command. The repository will have newly added file, only when you do SVN commit. Now let us add a new file called “thegeekstuff” to our repository.
  • Create a file in local working copy
  • $ ls -l /home/sasikala/cfg/thegeekstuff
    -rw-r--r-- 1 sasikala root 8 Apr 16 11:33 thegeekstuff
  • Add the file into SVN repository
  • svn add filename will add the files into SVN repository.
    $ svn add thegeekstuff
    A thegeekstuff
  • Commit the added the file
  • Until you commit, the added file will not be available in the repository.
    $ svn commit -m "Adding a file thegeekstuff" thegeekstuff
    Adding thegeekstuff
    Transmitting file data .
    Committed revision 814.

5. SVN Delete – Removing a file from repository

SVN delete command deletes an item from the working copy (or repository). File will be deleted from the repository when you do a SVN commit.
Syntax:
$ svn delete URL
Now let us remove the recently created file called “thegeekstuff”.
$ svn delete thegeekstuff
D thegeekstuff

$ svn commit -m "Removing thegeekstuff file" thegeekstuff
Deleting thegeekstuff
Committed revision 814.
Now you can do svn list and check whether the file was deleted from the repository.

6. SVN Diff – Display the difference

SVN diff displays the differences between your working copy and the copy in the SVN repository. You can find the difference between two revisions and two paths etc.,
Syntax:
$ svn diff filename

$ svn -r R1:R2 diff filename
The above example compares the filename@R1 and filename@R2.
Now the content of the file thegeekstuff looks like this,
$ cat /home/sasikala/cfg/thegeekstuff
testing
I edited the content of thegeekstuff file from testing to tester, which is shown below using the svn diff command.
$ svn diff thegeekstuff
Index: thegeekstuff
===================================================================
--- thegeekstuff (revision 815)
+++ thegeekstuff (working copy)
@@ -1 +1 @@
-testing
+tester

7. SVN Status – Status of the working copy

Use svn status command to get the status of the file in the working copy. It displays whether the working copy is modified, or its been added/deleted, or file is not under revision control, etc.
Syntax:

$ svn status PATH
The following example shows the status of my local working copy,
$ svn status /home/sasikala/cfg
M /home/sasikala/cfg/ftp_user.cfg
M /home/sasikala/cfg/geekstuff
‘M’ represents that the item has been modified. “svn help status” command will explain various specifiers showed in SVN status command.

8. SVN Log – Display log message

As we discussed in the beginning of this article, SVN remembers every change made to your files and directories. To know all the commits made in a file or directory, use SVN log command.
Syntax:

$ svn log PATH
The following displays all the commits made on thegeekstuff file
$ svn log thegeekstuff
------------------------------------------------------------------------
r815 | sasikala | 2011-04-16 05:14:18 -0700 (Sat, 16 Apr 2011) | 1 line

Adding a file thegeekstuff
------------------------------------------------------------------------
Since we made only one commit in the file thegeekstuff, it shows only one log message with the details.

9. SVN Move – Rename file or directory

This command moves a file from one directory to another or renames a file. The file will be moved on your local sandbox immediately (as well as on the repository after committing).
Syntax:
$ svn move src dest
The following command renames the file “thegeekstuff” to “tgs” in a single stroke.
$ svn move thegeekstuff tgs
A tgs
D thegeekstuff

$ ls
.# .. .svn email_user.cfg ftp_user.cfg inventory.cfg tgs
Now the file is renamed only in the working copy, not in the repository. To make the changes permanent, you need to commit the changes.
$ svn commit -m "Renaming thegeekstuff to tgs" tgs
Adding tgs
Transmitting file data .
Committed revision 816.

10. SVN Update – Update the working copy.

svn update command brings changes from the repository into your working copy. If no revision is specified, it brings your working copy up-to-date with the HEAD revision. Otherwise, it synchronizes the working copy to the revision given in the argument.
Always before you start working in your working copy, update your working copy. So that all the changes available in repository will be available in your working copy. i.e latest changes.
Syntax:

$ svn update PATH
In case some other user added/deleted file in URL, https://www.thegeekstuff.com/project/branches/release/migration/data/cfg, your working copy will not have those files by default, until you update your working copy.
$ svn update
A new/usercfg
A new/webcfg
Updated to revision 819.
In the above svn update command output, A represents that this file is “Added” to the working copy.

Friday, April 15, 2011

Sometimes Linux Admin / Programmer End-up Doing DBA Work


Sometimes Linux administrator or programmer may end-up doing some basic DBA operations on development database. So, it is important for non-DBAs to understand some basic database administration activities.

it's been my experience that the Linix administration or programmer will forget the part..

On development database.

Many times when we come across companies where they don’t have an in-house DBA and the development staff or system administrator is also providing DBA support when we audit the database backups they fail the audit.
What make’s a good programmer are not the same skills that make a good database administrator. What make’s a good database administrator are not the skills that make a good programmer.

I commend this person for wanting to teach programmers some basic DBA operations. I guarantee the point “on development database” will be lost. This has the potential recipe for disaster written all over it. 
My last blog was titled Death By Delete talks about a company that went to a hosting provider that offered package for hosting, website and database. It was such a great bargain till the first bill came in. The worst part was a developer was working in the production database and accidently deleted it all. They lost the entire database and more importantly went into bankruptcy as a result of it all. To read the original story...
That why when people send the support of their database to the lowest bidder I shutter violently. They are risking their whole business to save a few dollars. Ask MegaPetCo who is no longer in business. I get just as worried when people think a good programmer or system admin is a replacement for a DBA. Companies in this economy are looking for ways to save money at every turn. If they think they can get by without a DBA they will try.

So when I read “For a DBA, starting up and shutting down of oracle database is a routine and basic operation. Sometimes Linux administrator or programmer may end-up doing some basic DBA operations on development database. So, it is important for non-DBAs to understand some basic database administration activities.”

Its like asking someone who is not a pilot to fly a plane. Lets just hope your not along for the ride when they get over there head.

For companies that think not having proper database administration of the databases their mission critical business applications reply on. Ask MegPetCo if that was such a good idea.

Oh yeah right, you can’t ask, they are no longer in business. 

The author of the blog I am commenting on was trying to pass good information along. There is nothing wrong with that. They also were smart enough to make the point...

On development database.

 lets hope all the readers of the blog are smart enough to understand this new found knowledge should on be used on ...

On development database.

 For those companies that think they don’t need solid database administration talent supporting their mission critical business applications think again or you could be the next victim of..

DEATH BY DELETE.


If you don’t think you can afford proper database administration support, then you have not looked at companies like Ntirety that offer Database Administration As a Service “TM”. It’s a very cost effective way to make sure your company does not suffer from

DEATH BY DELETE.


For those of you that still want to learn more about the blog I referenced here is a sample with a link at the end to the site....

How To Startup Oracle Database

1. Login to the system with oracle username

Typical oracle installation will have oracle as username and dba as group. On Linux, do su to oracle as shown below.
$ su - oracle

2. Connect to oracle sysdba

Make sure ORACLE_SID and ORACLE_HOME are set properly as shown below.
$ env | grep ORA
ORACLE_SID=DEVDB
ORACLE_HOME=/u01/app/oracle/product/10.2.0

You can connect using either “/ as sysdba” or an oracle account that has DBA privilege.
$ sqlplus '/ as sysdba'
SQL*Plus: Release 10.2.0.3.0 - Production on Sun Jan 18 11:11:28 2009
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production
With the Partitioning and Data Mining options
SQL>

3. Start Oracle Database

The default SPFILE (server parameter file) is located under $ORACLE_HOME/dbs. Oracle will use this SPFILE during startup, if you don’t specify PFILE.

Oracle will look for the parameter file in the following order under $ORACLE_HOME/dbs. If any one of them exist, it will use that particular parameter file.
  1. spfile$ORACLE_SID.ora
  2. spfile.ora
  3. init$ORACLE_SID.ora

Type “startup” at the SQL command prompt to startup the database as shown below.
SQL> startup
ORACLE instance started.

Total System Global Area 812529152 bytes
Fixed Size 2264280 bytes
Variable Size 960781800 bytes
Database Buffers 54654432 bytes
Redo Buffers 3498640 bytes
Database mounted.
Database opened.
SQL>

If you want to startup Oracle with PFILE, pass it as a parameter as shown below.
SQL> STARTUP PFILE=/u01/app/oracle/product/10.2.0/dbs/init.ora

How To Shutdown Oracle Database

Following three methods are available to shutdown the oracle database:
  1. Normal Shutdown
  2. Shutdown Immediate
  3. Shutdown Abort

1. Normal Shutdown

During normal shutdown, before the oracle database is shut down, oracle will wait for all active users to disconnect their sessions. As the parameter name (normal) suggest, use this option to shutdown the database under normal conditions.
SQL> shutdown
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>

2. Shutdown Immediate

During immediate shutdown, before the oracle database is shut down, oracle will rollback active transaction and disconnect all active users. Use this option when there is a problem with your database and you don’t have enough time to request users to log-off.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>

Hypervisor and their virtual disk formats


HYPERVISORFORMAT
VirtualBoxVMDK Stream Optimized
VirtualBoxRAW
VirtualBoxVMDK Flat
VirtualBoxVMDK Sparse
VirtualBoxVHD Flat Disk
VirtualBoxVDI Fixed Disk
VirtualBoxVDI Sparse Disk
KVMRAW
KVMVMDK Flat
KVMVMDK Sparse
KVMVHD Flat
KVMVHD Sparse
KVMQCOW2 Flat
KVMQCOW2 Sparse
XENRAW
XENVMDK Flat
XENVMDK Sparse
XENVHD Flat
XENVHD Sparse
VMWARERAW
VMWAREVMDK Flat
VMWAREVMDK Sparse
Hyper-VVHD Flat
Hyper-VVHD Sparse


Oracle architecture and its categories

Oracle architecture is described in three categories:

* User related process
* Instance(Logical memory structure) and
* Physical file structure

Instance + Database= Oracle server

User Process : Whenever a user wants to connect to the oracle server for extraction of the data or to insert any data using sql statement. The user process then initiates a connection and hence a session is established for the user in the instance. After establishing a session, each user then starts a server process which will actually allow the user to interact to the database and retrieve the data or insert it. To be precise, Server process communicates with the oracle instance on behalf of the user. An additional memory structure called PGA (Program Global Area) is also created during this process. It stores the user session variables and bind variables.

Oracle Instance: Oracle instance is made up of SGA (System Global Area) and Background process. SGA further divided into three main components.

* Shared Pool: Caches the recently used sql statements.
Database Buffer cache: Cashes the data that has been most recently used by the user.
Redo log buffer: Stores transaction information.

Oracle uses LRU (Least Recently Used) algorithm.

It will caches the most recently used sql statements in shared pool and data in buffer cache. If for example we as a user1 are entering a sql statement (select * from emp). This statement will be cached by the shared pool and the data which is extracted will be cached in Database buffer cache. Now if any other user wants the same data, obviously he is going to use the same sql statement, so the data will be presented to the user directly from the database buffer thus improving the performance.

SGA size can be allocated manually or automatically. This is determined by the settings in a configuration file called parameter initialization file.

How to reduce size of tablespace


If temp is the tablespace that need to be reduced
 
1. Create new temp1 tablespace
2. Make new temp1 tablespace as default
3. Drop the temp tablespace
4. create  temp tablespace
5. Make the temp tablepsace as default
6. Drop  temp1  tablespace..


Common Scripting errors for beginners


when i  started scripting i had these errors in the begenning . The most common mistakes one makes during his initial stages of scripting are.

1.Check script file permissions. A script needs execute permission


2.We should not use default values that generate errors.If you
  give those your script execution breaks in the middle.

3.We must supply parameters as required ie make parameter mandatory
  if parameter is to be provided for sure, or else it throws an error.

4. Resuable script should not be hard-coded values.Use parameters  instead.

5.Commenting the script is very important... Make it a habbit to write
  comments.Also specify in comments if script has multiple parameters.
  you can also write examples in comments for better understanding.

6. Error handling is a must for scripting