Debian 软连接的备份与恢复
一 备份策略选择
二 仅备份软连接清单的可移植做法
find /path/to/search -type l -exec ls -l {} \; > symlinks_backup.txt
find /path/to/search -type l -printf '%p %l\n' > symlinks.list
while IFS= read -r line; do
# 兼容含空格的路径:第9列为链接路径,最后一列为目标路径
set -- $line
link=$9
# 目标可能在第10或第11列(取决于是否显示时间/年份)
if [ -n "$11" ]; then target=$11; else target=$10; fi
mkdir -p "$(dirname "$link")"
ln -sfn "$target" "$link"
done < symlinks_backup.txt
while read -r link target; do
mkdir -p "$(dirname "$link")"
ln -sfn "$target" "$link"
done < symlinks.list
三 连同目标内容一起备份
rsync -a --progress /path/to/source/ /path/to/backup/
rsync -a -l --progress /path/to/source/ /path/to/backup/
四 注意事项与实用建议