SCP与亚马逊的问题与副本

时间:2014-09-17 17:28:02

标签: bash shell amazon-web-services amazon-ec2 sh

有人可以帮我弄清楚我收到错误的原因:/home/cpmove-XXXXX.tar.gz is not a directory

我正在尝试将网站从一个cpanel服务器批量打包到亚马逊上现有的另一个,这是我的代码......上面的错误显示在MOVINGDONE MOVING之间(这就是为什么我认为它是scp)

#!/bin/bash

# -------------------------------------------------
# -------------------------------------------------
# Setup the function that will do the actual backup
run_backup(){
    LOGFILE=/batch-move.log
    # Package the account
    ./scripts/pkgacct $1;
    echo '##########################################' >> $LOGFILE;
    echo "# Start: date +'%T'" >> $LOGFILE;
    echo "# Backing Up: $1" >> $LOGFILE;
    echo '##########################################' >> $LOGFILE;
    # Upload it to Server Specified on Amazon
    # 2nd Param = Server IP Address
    if [ ! -f MYPEMFILE.pem ]
        then
        wget http://MYSTI.COM/MYPEMFILE.pem;
    fi;
    sudo chmod 400 MYPEMFILE.pem;
    echo 'MOVING';
    scp -i MYPEMFILE.pem /home/cpmove-$1.tar.gz root@$2:/home /home/cpmove-$1.tar.gz;
    echo 'DONE MOVING';
    echo '##########################################' >> $LOGFILE;
    echo "# Uploading Backup: $1" >> $LOGFILE;
    echo '##########################################' >> $LOGFILE;
    echo '##########################################' >> $LOGFILE;
    echo "# Removing Backup Up: $1" >> $LOGFILE;
    echo "# Finish: date +'%T'" >> $LOGFILE;
    echo '##########################################' >> $LOGFILE;
}


# -------------------------------------------------
# -------------------------------------------------
# Use a space-delimited list of single-quoted
# strings of the usernames to batch
# if it's empty it will backup all user directories
# in /home
# -------------------------------------------------
# -------------------------------------------------
USER_ACCOUNT=();


# Loop through the user array
# If it's empty, then get all users in the /home 
# directory, based on each folder
# do not include root user
if [ ${#USER_ACCOUNT[@]} -eq 0 ]; then
    for filename in /home/* ; do
        # Get the owner of $filename.
        ACCT=$(stat -c '%U' "$filename");
        # If the file is a directory NOT owned by root, run backup.
        if [ -d "$filename" -a "$ACCT" != "root" ]; then
            # Uncomment when satisfied
            run_backup $ACCT $1;
            # Remove the file from the server
            echo 'REMOVING /home/cpmove-$ACCT.tar.gz';
            /bin/rm -f /home/cpmove-$ACCT.tar.gz;
    fi;
    done;
else
    # we have our list, now loop through them all
    for i in ${!USER_ACCOUNT[@]}; do
        # Assign an account variable
        ACCT=${USER_ACCOUNT[$i]};
        run_backup $ACCT $1;
        # Remove the file from the server
        echo 'REMOVING /home/cpmove-$ACCT.tar.gz';
        /bin/rm -f /home/cpmove-$ACCT.tar.gz;
    done;
fi;

1 个答案:

答案 0 :(得分:1)

这一行是你的问题:

scp -i MYPEMFILE.pem /home/cpmove-$1.tar.gz root@$2:/home /home/cpmove-$1.tar.gz;

您告诉scp将/home/cpmove-$1.tar.gzroot@$2:/home移至/home/cpmove-$1.tar.gz,并且由于/home/cpmove-$1.tar.gz不是目录,因此scp无法将多个源文件/目录移动到该目录。

删除最后的/home/cpmove-$1.tar.gz,因为它不是你想要的。

另外,您应引用变量用法"$1""$2"等。