Rsync bash 脚本和硬链接文件

发布于 2024-09-12 16:30:53 字数 864 浏览 4 评论 0原文

我正在创建一个 bash 脚本来使用 rsync 备份我的文件。

备份全部来自一个目录。 我只想备份新的或修改的文件。

目前,我告诉 rsync 备份目录,并检查与上次备份相比的文件。

我这样做的方式是

THE_TIME=`date "+%Y-%m-%dT%H:%M:%S"`
rsync -aP --link-dest=/Backup/Current /usr/home/user/backup /Backup/Backup-$THE_TIME
rm -f /Backup/Current
ln -s /Backup/Backup-$THE_TIME /Backup/Current

我很确定我的语法是正确的。每个备份都会检查“当前”文件夹,并仅在必要时上传。然后,它将删除当前文件夹,并重新创建指向刚刚执行的最新备份的符号链接。

当我运行脚本时出现错误:

rsync:链接“/Backup/Backup-2010-08-04-12:21:15/dgs1200series_manual_310.pdf”

=> /备份/当前/dgs1200series_manual_310.pdf 失败:不支持操作(45)

主机操作系统正在运行 HFS 文件系统,该系统支持硬链接。我试图弄清楚是否有其他东西不支持这一点,或者我的代码是否有问题。

感谢您的任何帮助

编辑:

我能够在本地计算机上创建硬链接。 我还可以在远程服务器上创建硬链接(本地登录时) 通过 afp 安装时,我无法在远程服务器上创建硬链接。即使这两个文件都存在于服务器上。

我猜这是 afp 的限制。

I am creating a bash script to backup my files with rsync.

Backups all come from a single directory.
I only want new or modified files to be backed up.

Currently, I am telling rsync to backup the dir, and to check the files compared to the last backup.

The way I am doing this is

THE_TIME=`date "+%Y-%m-%dT%H:%M:%S"`
rsync -aP --link-dest=/Backup/Current /usr/home/user/backup /Backup/Backup-$THE_TIME
rm -f /Backup/Current
ln -s /Backup/Backup-$THE_TIME /Backup/Current

I am pretty sure I have the syntax correct for this. Each backup will check against the "Current" folder, and upload only as necesary. It will then delete the Current folder, and re-create the symlink to the newest backup it just did.

I am getting an error when I run the script:

rsync: link "/Backup/Backup-2010-08-04-12:21:15/dgs1200series_manual_310.pdf"

=> /Backup/Current/dgs1200series_manual_310.pdf
failed: Operation not supported (45)

The host OS is running HFS filesystem, which supports hard linking. I am trying to figure out if something else is not supporting this, or if I have a problem in my code.

Thanks for any help

Edit:

I am able to create a hard link on my local machine.
I am also able to create a hard link on the remote server (when logged in locally)
I am NOT able to create a hard link on the remote server when mounted via afp. Even if both files exist on the server.

I am guessing this is a limitation of afp.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

平安喜乐 2024-09-19 16:30:53

以防万一您的命令行只是一个示例:请务必始终使用绝对路径名指定链接目标目录!这是我花了很长时间才弄清楚的事情……

Just in case your command line is only an example: Be sure to always specify the link-dest directory with an absolute pathname! That’s something which took me quite some time to figure out …

任谁 2024-09-19 16:30:53

手册页中有两件事值得检查:

如果文件未链接,请仔细检查其属性。还
检查某些属性是否被强制置于 rsync 之外
控制,这样一个安装选项,将 root 压缩为一个
用户,或安装具有通用所有权的可移动驱动器(例如
如 OS X 的“忽略此卷的所有权”选项)。

请注意,2.6.1 之前的 rsync 版本有一个错误,可能会导致
防止非超级用户 --link-dest 正常工作
当指定 -o 时(或由 -a 暗示)。你可以解决
通过在发送到旧的 rsync 时避免使用 -o 选项来解决此错误。

您是否打开了“忽略所有权”选项?您拥有什么版本的rsync

另外,您是否尝试过在命令行中使用 ln 手动创建类似的硬链接?

Two things from the man page stand out that are worth checking:

If file's aren't linking, double-check their attributes. Also
check if some attributes are getting forced outside of rsync's
control, such a mount option that squishes root to a single
user, or mounts a removable drive with generic ownership (such
as OS X's “Ignore ownership on this volume” option).

and

Note that rsync versions prior to 2.6.1 had a bug that could
prevent --link-dest from working properly for a non-super-user
when -o was specified (or implied by -a). You can work-around
this bug by avoiding the -o option when sending to an old rsync.

Do you have the "ignore ownership" option turned on? What version of rsync do you have?

Also, have you tried manually creating a similar hardlink using ln at the command line?

抱猫软卧 2024-09-19 16:30:53

我不知道这是否是同一个问题,但我知道当目标是 FAT32 分区并且文件名中包含“:”(冒号)时,rsync 无法同步文件。 [源文件系统是 ext3,目标是 FAT32]

尝试重新配置 date 命令,使其不使用冒号,看看是否有影响。

例如

THE_TIME=`date "+%Y-%m-%dT%H_%_%S"`

I don't know if this is the same issue, but I know that rsync can't sync a file when the destination is a FAT32 partition and the filename has a ":" (colon) in it. [The source filesystem is ext3, and the destination is FAT32]

Try reconfiguring the date command so that it doesn't use a colon and see if that makes a difference.

e.g.

THE_TIME=`date "+%Y-%m-%dT%H_%_%S"`
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文