こんにちは、このコードを使用してバックアップ ファイルを生成し、ディレクトリ内の最新ファイルを見つけて、その最新ファイルを ip を使用してサーバーにコピーしました。問題は、最新ファイルをサーバーにコピーしていないことです。これを行う方法は?
ここに私が使用したコードがあります:
#!/bin/sh
#
#Defines our output file
OUTPUTDIR=/home/backup
OUTPUT=$OUTPUTDIR/backup-of-$(date +%d-%m-%Y).zip
BACKUPDIR="/home/user/Desktop/backup/"
LATESTFILE=ls -t1 | head -n1
#Display message about starting the backup
echo "Starting backup of directory $BACKUPDIR to file $OUTPUT"
#Start the backup
zip -r $OUTPUT $BACKUPDIR
#Checking the status of the last process:
if [ $? == 0 ]; then
#Display confirmation message
echo "The file:"
echo $OUTPUT
echo "was created as a backup"
else
#Display error message message
echo "There was a problem creating:"
echo $OUTPUT
echo "as a backup for:"
echo $BACKUPDIR
fi
echo "Please Enter The IP to save backup file"
read ip
echo "Connecting to" $ip. please wait...
scp $LATESTFILE user@$ip:/home/user/Desktop