LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Shell script to copy database archivelogs sequentially from one directory to another (https://www.linuxquestions.org/questions/programming-9/shell-script-to-copy-database-archivelogs-sequentially-from-one-directory-to-another-730125/)

rajeshkumar.dba 06-02-2009 07:25 AM

Shell script to copy database archivelogs sequentially from one directory to another
 
Hi Friends,
I am a dba and new to scripting and i want to write a shell script to copy database archivelog files sequential from one directory to another directory within a server. I am hereby enclosing the sample archivelog file name.

Archive log filename : log_0000118432_1.arc (Here number 0000118432 will be sequentially incremented by 1 for next filename).

Here the catch is all Archivelogs must be copied to destination directory. Previously copied files should not be copied. Any help or layout of this script would be much appreciated. Thanks a lot in advance.

Regards,
Rajeshkumar

MensaWater 06-02-2009 08:01 AM

Quote:

Previously copied files should not be copied
You should use the rsync command to copy the files if the previously copied files are still in the target directory. It can do many things and most commonly is used to keep two directories in sync. It only copies in the differences and can even be used to delete files in the target that no longer exist in the source if you want.

Type "man rsync" for details.

ghostdog74 06-02-2009 08:12 AM

Code:

awk 'BEGIN{
  destination="/tmp/"
  q="\042"
}
function exists(file,        dummy, ret) {
  ret=0;
  if ( (getline dummy < file) >=0 ) {ret = 1; close(file)};
  return ret;
}
{
  if ( exists(destination FILENAME) ){
    print "file "FILENAME " exists..not copying..."
  }else{
    cmd="cp "q FILENAME q " "destination
    cmd|getline result
  }

}' log*.arc


ghostdog74 06-02-2009 08:12 AM

Code:

deleted...


All times are GMT -5. The time now is 10:19 PM.