大家好,我已经使用此代码生成备份文件,在目录中查找最新文件并使用 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