FTP 서버에 업로드된 파일을 추출할 수 없습니다.

FTP 서버에 업로드된 파일을 추출할 수 없습니다.

소스 시스템:

  • 센트OS 7
  • 배쉬 쉘
  • 지퍼

대상 시스템:

  • FTP 서버
  • 센트OS 6.4
  • 배쉬 쉘
  • 압축을 풀다

파일을 보관하고 쉘 스크립트를 사용하여 FTP 서버로 보내는 스크립트를 작성했습니다.

#!/bin/bash

# Declare no. of days
days=15

# Declare Source path of sql files and Destination path of backup directory
dumps=/home/applications/backup

bkpdir=/home/applications/backup/olddumps

# Find sql dumps of ets
files=($(find $dumps/*.sql -mtime +"$days"))

for file in ${files[*]}

do
# Move each file into backup dir which is 15 days old
echo "file is: $file\n";

mv $file $bkpdir

# Find the sql files and compress them

cd $bkpdir

filename=$(basename $file)

zip $bkpdir/$filename.zip $filename

# FTP Login

HOST=a.b.c.d

USER=xxxx

PASS=yyyyy

REM_DIR=/olddumps/sqlfiles

echo "Uploading file via FTP:"

ftp -in $HOST <<EOF

quote USER $USER

quote PASS $PASS

cd $REM_DIR

put $filename.zip

bye

EOF

# Remove sql files if any
rm $bkpdir/$filename

done

# Remove compressed files which are 6 months old
find $bkpdir/*.zip -type f -mtime +180 -exec rm {} \;

이제 문제는 대상 시스템의 압축 파일이 unzip명령을 사용하여 추출되지 않고 다음 오류를 표시한다는 것입니다.

아카이브: emt_bus-08-09-16-03-29.sql.zip

caution: zipfile comment truncated
error [emt_bus-08-09-16-03-29.sql.zip]: missing 49666528 bytes in zipfile
(attempting to process anyway)
error [emt_bus-08-09-16-03-29.sql.zip]: start of central directory not found;
zipfile corrupt.
(please check that you have transferred or created the zipfile in the
appropriate BINARY mode and that you have compiled UnZip properly)

아카이브를 사용했지만 tar운이 없었습니다. 대상 시스템에서 파일을 추출하지 않고 다음 오류가 표시됩니다.

gzip: stdin: invalid compressed data--format violated
emt_bus-08-09-16-03-29.sql
tar: Unexpected EOF in archive
tar: Unexpected EOF in archive
tar: Error is not recoverable: exiting now

문제를 해결하는 방법은 무엇입니까?

답변1

해당 스크립트를 실행할 때 표시되지 않는 오류 메시지가 이미 있을 수 있습니다.


script.sh > log.txt 2>&1 로 실행하여 모든 출력을 로그에 캡처합니다.

마지막 부분은 stderr를 stdout으로 리디렉션합니다(이 경우 log.txt).

아마도 당신이 발견하게 될 것은 시간 초과(전송하는 파일 수, 연결의 안정성)이거나 다음 명령을 기다린다고 생각하는 명령이 실제로 스크립트에서 기다리지 않는다는 것입니다.

답변2

스크립트는 binary( quote명령 다음에) 설정되어야 합니다. 그렇지 않으면 이 스크립트에 대해 텍스트 모드를 사용합니다.

대화형이라면 방금 테스트한 ftp 클라이언트는 바이너리 모드를 가정합니다. 그러나 비대화형인 경우에는 그렇지 않습니다.

이것이 제가 테스트하고 수정한 내용입니다.

#!/bin/sh
ftp -in invisible-island.net <<EOF
quote USER anonymous
quote PASS anonymous
binary
cd cproto
get cproto.tar.gz
bye
EOF

관련 정보