我有一个脚本将 Amazon S3 存储桶附加为我的 CentOS 6.5 机器上的挂载点
我正在尝试利用 rsync 将文件从 2 个位置复制到存储桶
代码:
#!/bin/bash
# SET THE BUCKET NAME HERE
S3_BUCKET="my-bucketname";
# SET THE MOUNT POINT HERE
MNT_POINT="/mnt/my-mountpoint";
# Create the mount point if it does not already exist, and set permissions on it
if [[ ! -e $MNT_POINT ]]; then
mkdir $MNT_POINT;
chmod -R 0777 $MNT_POINT;
fi;
# Mount the bucket
riofs -c ~/.config/riofs/riofs.conf.xml -o rw,allow_other,umask=2777,uid=1000,gid=1000 --cache-dir=/tmp/cache $S3_BUCKET $MNT_POINT;
mkdir $MNT_POINT/home;
mkdir $MNT_POINT/mysqlbak;
# Copy all "User" directories, except those owned by root
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
# Rsync to the mount
rsync -a /home/$filename $MNT_POINT/home;
fi;
done;
# Copy all mysql backups
for mysqlbak in /mysqlbak/* ; do
# Rsync to the mount
rsync -a /mysqlbak/$mysqlbak $MNT_POINT/mysqlbak;
done;
# No need to keep it mounted
umount $MNT_POINT;
如您所见,我正在尝试保留/mysqlbackup 文件夹内容的备份,以及/home 的内容(减去根帐户附加的任何内容)
问题是,当我在我的服务器上运行此脚本时,出现以下错误:
rsync: change_dir "/home//home" failed: No such file or directory (2)
rsync error: some files/attrs were not transfered (see previous errors) (code 23) at main.c(1039) [sender=3.0.6]
和
rsync: change_dir "/mysqlbak//mysqlbak" failed: No such file or directory (2)
rsync error: some files/attrs were not transfered (see previous errors) (code 23) at main.c(1039) [sender=3.0.6]
我可以向你保证/home 和/mysqlbak 都存在。
我怎样才能解决这个问题,以便它正确地同步到这个坐骑?
/home 和/mysqlbak 没有在 bucket 中创建
最佳答案
替换
rsync -a /home/$filename $MNT_POINT/home;
通过
rsync -a $filename $MNT_POINT/home;
并替换
rsync -a /mysqlbak/$mysqlbak $MNT_POINT/mysqlbak;
通过
rsync -a $mysqlbak $MNT_POINT/mysqlbak;
关于linux - rsync bash 脚本复制目录结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26414194/