.lzo 파일을 scp한 다음 .lzo 파일의 압축을 풀고 삭제합니다.

.lzo 파일을 scp한 다음 .lzo 파일의 압축을 풀고 삭제합니다.

.lzo원격 서버에서 파일을 복사하는 스크립트가 있습니다. 스크립트는 세 서버 각각에서 복제를 시도하며, 서버 중 하나에 오류가 발생하면 이메일이 전송됩니다.

내 스크립트는 다음과 같으며 예상대로 작동합니다.

export status_dir=$(mktemp -t -d transfer.XXXXXX)
cleanup() { rm -rf "$status_dir"; }
trap cleanup 0 # automatically clean up on exit

do_Copy() {
  el=$1
  PRIMSEC=$2
  scp david@"$local_dc":"$dir3"/new_clients_2014_"$el"_200003_5.data.lzo "$PRIMSEC"/. \
    || { touch "$status_dir/local_down" && scp david@"$remote_dc_1":"$dir3"/new_clients_2014_"$el"_200003_5.data.lzo "$PRIMSEC"/.; } \
    || { touch "$status_dir/primary_down" && scp david@"$remote_dc_2":"$dir3"/new_clients_2014_"$el"_200003_5.data.lzo "$PRIMSEC"/.; } \
    || { touch "$status_dir/secondary_down"; exit 1; }
}

parallel -j 12 do_Copy {} $PRIMARY ::: "${PARTITION_DATA_1[@]}" &
parallel -j 12 do_Copy {} $SECONDARY ::: "${PARTITION_DATA_2[@]}" &
wait

[[ -e "$status_dir/local_down" ]] && \
   mailx -r "[email protected]" -s "$local_dc machine down" "[email protected]" \
     <<<"Local machine $local_dc was down, so copied from Primary Remote machine $remote_dc_1"

[[ -e "$status_dir/primary_down" ]] && \
   mailx -r "[email protected]" -s "$remote_dc_1 machine down" "[email protected]" \
     <<<"Primary Remote machine $remote_dc_1 was down, so copied from Secondary Remote machine $remote_dc_2"

[[ -e "$status_dir/secondary_down" ]] && \
   mailx -r "[email protected]" -s "All three machine's are down" "[email protected]" \
     <<<"All three machines are down. Exiting out."

위 스크립트가 완료된 후 두 번째 스크립트를 실행하여 모든 .lzo파일의 압축을 풀고 삭제합니다.

#!/bin/bash
set -e
export PRIMARY=/test01/primary
export SECONDARY=/test02/secondary

parallel lzop -dU -- ::: {"$PRIMARY","$SECONDARY"}/*.lzo

이 두 스크립트를 결합하고 싶습니다. 두 번째 파일을 실행하는 대신 첫 번째 파일도 압축을 풀고 삭제하도록 합니다 .lzo. 아래의 코드 블록만 수정된다고 가정하고 있는데, 머신 다운 여부를 확인하기 위해 사용하는 테스트 때문에 무엇을 추가해야 할지 잘 모르겠습니다.

do_Copy() {
  el=$1
  PRIMSEC=$2
  scp david@"$local_dc":"$dir3"/new_clients_2014_"$el"_200003_5.data.lzo "$PRIMSEC"/. \
    || { touch "$status_dir/local_down" && scp david@"$remote_dc_1":"$dir3"/new_clients_2014_"$el"_200003_5.data.lzo "$PRIMSEC"/.; } \
    || { touch "$status_dir/primary_down" && scp david@"$remote_dc_2":"$dir3"/new_clients_2014_"$el"_200003_5.data.lzo "$PRIMSEC"/.; } \
    || { touch "$status_dir/secondary_down"; exit 1; }
}

결합된 스크립트가 최선의 선택입니까? 아니면 이전에 하던 일을 계속하고 두 개의 스크립트를 가져야 합니까? 지금처럼 하면 .lzo압축되지 않은 파일을 동시에 보관했다가 나중에 삭제하기 위해 더 많은 디스크 공간이 필요합니까?.lzo

답변1

물론, 결합할 수도 있습니다. 서버가 시작되는지 여부는 전혀 관련이 없습니다. 어떤 서버에서 다운로드하든 .lzo파일은 항상 같은 위치에 있습니다. 또한 스크립트가 1개든 2개든 필요한 디스크 공간에는 차이가 없습니다. 왜 이렇게 되어야 할까요? 두 경우 모두 동일한 파일의 압축을 풀고 있습니다. 복사 기능에 두 번째 스크립트의 줄을 추가하기만 하면 됩니다.

do_Copy() {
  el=$1
  PRIMSEC=$2
  scp david@"$local_dc":"$dir3"/new_clients_2014_"$el"_200003_5.data.lzo "$PRIMSEC"/. \
    || { touch "$status_dir/local_down" && scp david@"$remote_dc_1":"$dir3"/new_clients_2014_"$el"_200003_5.data.lzo "$PRIMSEC"/.; } \
    || { touch "$status_dir/primary_down" && scp david@"$remote_dc_2":"$dir3"/new_clients_2014_"$el"_200003_5.data.lzo "$PRIMSEC"/.; } \
    || { touch "$status_dir/secondary_down"; exit 1; }
}

PRIMARY=/test01/primary
SECONDARY=/test02/secondary

parallel lzop -dU -- ::: {"$PRIMARY","$SECONDARY"}/*.lzo

관련 정보