sh 从安装在Linux机器上的Time Machine卷复制数据。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 从安装在Linux机器上的Time Machine卷复制数据。相关的知识,希望对你有一定的参考价值。

#!/bin/bash
# 
# Copy data from a Time Machine volume mounted on a Linux box.
#
# Usage: copy-from-time-machine.sh <source> <target>
#
# source: the source directory inside a time machine backup
# target: the target directory in which to copy the reconstructed
#         directory trees. Created if it does not exists.
#
# Details:
#
# Time machine implements directory hard links by creating an
# empty file in place of the directory and storing in its
# "number of hard links" metadata attribute a pointer to a
# real directory in "/.HFS Private directory data^M" named
# "dir_$number".
#
# This script reconstructs a plain directory tree from this
# really ugly apple hack. Tested on a 650GB backup from OSX
# 10.6 mounted on a Linux 3.2.0-38 Ubuntu box. YMMV.
#
# MIT License.
# 
#  - vjt@openssl.it
#

self="$0"
source="$1"
target="$2"
hfsd="$3"

set -e

if [ -z "$source" -o -z "$target" ]; then
  echo "Usage: $self <source> <target>"
  exit -1
fi

if [ ! -d "$target" ]; then
  mkdir -p "$target"
fi

if [ -z "$hfsd" ]; then
  # Look for HFS Private directory data
  sysname="$(echo -ne '.HFS+ Private Directory Data\r')"
  hfsd=$source
  while [ "$hfsd" != "/" -a ! -d "$hfsd/$sysname" ]; do
    hfsd=`dirname "$hfsd"`;
  done

  if [ "$hfsd" = '/' ]; then
    echo "HFS Private Directory Data not found in $source, is it an HFS filesystem?"
    exit -2
  else
    echo "HFS Private Directory Data found in '$hfsd'"
    hfsd="$hfsd/$sysname"
  fi
fi

find "$source" -mindepth 1 -maxdepth 1 -and -not -name . -and -not -name .. | while read entry; do
  dest="$target/`basename "$entry"`"
  read hlnum type <<<$(stat -c '%h %F' "$entry")

  case $type in
    'regular file'|'symbolic link')
      cp -van "$entry" "$dest"
      ;;

    'directory')
      # Recurse
      $self "$entry" "$dest" "$hfsd"
      ;;

    'regular empty file')
      if [ -d "$hfsd/dir_$hlnum" ]; then
        # Recurse
        $self "$hfsd/dir_$hlnum" "$dest" "$hfsd"
      else
        echo "Skipping empty file $entry"
      fi
      ;;
  esac

done

以上是关于sh 从安装在Linux机器上的Time Machine卷复制数据。的主要内容,如果未能解决你的问题,请参考以下文章

sh 在Linux机器上安装Groovy脚本

(何时)CACurrentMediaTime/mach_system_time 在 iOS 上是不是环绕?

linux怎么远程执行另一台linux机器上的shell文件?

如何使用 mach_absolute_time 而不会溢出?

格式无关的二进制对象?

Shell 脚本文件(.sh)不能从 Linux 上的 c# 核心运行