Find the answer to your Linux question:
Results 1 to 7 of 7
Iam having one script that will basically inform the group of user whether the specific dump file exist on 4 specific server or not.But now I want to modify the ...
  1. #1
    Just Joined!
    Join Date
    Dec 2011
    Posts
    11

    How to modify the script to copy dump files

    Iam having one script that will basically inform the group of user whether the specific dump file exist on 4 specific server or not.But now I want to modify the script such that if that dumpfile is not their in one server we can use SCP from one server to copy the dump file automatically when that script ran.

    My Initial thinking is that we can assume one server will always be having that dump file so we can take this as a base server.And can compare it with rest of the server for the dumpfile so that it matches it and if it is not their can copy the same.

    Let me know if someone have some other idea or some short script to perform this Task.

    Thanks in Advance

  2. #2
    Just Joined!
    Join Date
    Dec 2011
    Posts
    11

    How to copy dump files on different server.

    I want to copy a dump file from one server to other server.I have 4 server lg105,lg256,lg278,lg340...I have one script which will check whether the dump file exist in this or not.

    Now suppose lg105m is having the dump file.I want to check it with other 3 server and if that dump file does not exist it do the SCP from lg105 and copy it to the server which is not having that dump file.

    Please help me if you guys have any idea regarding it.

  3. #3
    Linux Guru
    Join Date
    May 2011
    Posts
    1,843
    I assume you have SSH keys set up (so that there are no password prompts and you can run fully autonomously).

    Let's assume the file is /data/file1.dmp.

    I'd do something like this:
    Code:
    #!/bin/bash
    
    # path to the dump file
    file=/data/dump1.dmp
    filepath=$(dirname $file)
    
    # make sure it exists
    if [ -f $file ]; then
    
      # get the MD5 checksum
      cksum=$(md5sum $file|awk '{print $1}')
      if [ -z "$cksum" ]; then
        echo "Failed to generate MD5 checksum for $file - aborting"
        exit 1
      fi
    else
      echo "$file: No such file"
      exit 1
    fi
    echo "Local file $file MD5 checksum:  $cksum"
    
    for rhost in lg256 lg278 lg340; do
      unset copy
      printf "\nRemote host $rhost:\n"
      out=$(ssh $rhost md5sum $file)
      if [ -z "$out" ]; then
        echo "Failed to get output from $rhost - will copy dump file"
        copy=1
      else
    
        # get MD5 checksum from output
        rcksum=$(echo $out|grep [[:space:]]\**$file$|awk '{print $1}')
        echo "Remote file $file MD5 checksum: $rcksum"
    
        # compare checksums
        if [ "$cksum" == "$rcksum" ]; then
          echo "Remote copy of $file is okay"
        else
          echo "Remote copy of $file is NOT okay - will copy dump file"
          copy=1
        fi
    
      fi
    
      # copy the dump file to the remote host
      if test $copy; then
        scp $file $rhost:$filepath/
      fi
    done
    Note that it will fail the scp of the file to the remote host if the directory does not first exist. You may need to play with how the MD5 checksum is read from the output of the ssh command.

  4. #4
    Just Joined!
    Join Date
    Dec 2011
    Posts
    11
    Thanks for the help Man..I will try to modify it and let you know..Thanks Again

  5. #5
    Just Joined!
    Join Date
    Dec 2011
    Posts
    11
    Basically we are using a common directory name where we are saving all the dump files.../apps/oraexports. for all the hosts.and this directory will exist always.So it should be working fine.

  6. #6
    Linux Guru
    Join Date
    May 2011
    Posts
    1,843
    Just a note - you could always use rsync instead of scp for this task, it seems more appropriate to me.

  7. #7
    Just Joined!
    Join Date
    Dec 2011
    Posts
    11
    Thanks for the Tip Atreyu..I will try it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...