我已经为我的linux机器写了一个备份脚本,它加密tarball并将其发送到一个远程服务器,其中包含配置的ssh密钥对的scp,但是当我运行它时,它给了我以下错误:第一个月
#!/bin/bash
# Define the date format for the filename
datetime=$(date +"%Y%m%d_%H%M")
# Define the source directory and the backup directory
src_dir="/var/www/html" # this is the directory that we will back up
backup_dir="/home/zero/Backup" # This is where we will temporarily store the encrypted backup data
# Create a tarball of the source directory
tar -czf $backup_dir/backup_$datetime.tar.gz $src_dir
# Read the password from a secure file
password=$(cat /home/zero/Backup/pwd)
# Encrypt the tarball using openssl
gpg --pinentry-mode=loopback --passphrase $password --symmetric --cipher-algo AES256 --output $backup_dir/backup_$datetime.tar.gz.gpg $backup_dir/backup_$datetime.tar.gz
rm $backup_dir/backup_$datetime.tar.gz
# Get the .gpg filename
filename=$(find /home/zero/Backup -type f -name "*.gpg" -print -quit)
# Check if a file was found
if [ -n "$filename" ]; then
# if file is found send it ove ssh to the remote server
send=scp $filename root@178.79.148.186:/root/Backup
echo "$(date): Backup Successful" >> /home/zero/Backup/backup.log
# remove file once it has been sent to remote server
rm -f $filename
else
# if file is not found display error msg
echo "$(date): No encrypted file found" >> /home/zero/Backup/backup.log
fi
字符串
备份成功,加密工作完美,但它不会发送到远程服务器。我在根配置文件的脚本,我运行它作为根.以下是文件权限:
drwxr-xr-x 2 zero zero 4096 Jul 31 12:51 .
drwx------ 37 zero zero 4096 Jul 31 12:40 ..
-rw-r--r-- 1 root root 3578 Jul 31 12:50 backup_20230731_1250.tar.gz.gpg
-rw-r--r-- 1 root root 3578 Jul 31 12:51 backup_20230731_1251.tar.gz.gpg
-rw-r--r-- 1 zero zero 96 Jul 31 12:51 backup.log
-rwx------ 1 root root 1465 Jul 31 12:51 backup_script.sh
-rw------- 1 root root 5 Jul 29 04:13 pwd
型
我的问题是:如何将其发送到远程服务器?
我试过更改文件权限,但我没有运气。
2条答案
按热度按时间k3bvogb11#
这是我最终想出的解决办法。感谢这个答案https://stackoverflow.com/a/76803519/20177543提到它没有执行权限
字符串
rbl8hiat2#
字符串
您忘记了这里的命令替换语法,它试图将
$filename
作为命令执行。我假设在这一点上,filename= /home/zero/Backup/backup_20230731_1251.tar.gz.gpg
和它没有 * 执行 * 权限。