為 OSX 內容備份編寫重複檔案複製操作腳本

為 OSX 內容備份編寫重複檔案複製操作腳本

設想:

  1. 使用相機將內容記錄到CF卡上。
  2. 將CF卡的內容複製到本機硬碟的指定資料夾中(例如20120311-D01)。我不介意更改腳本來更新我想要使用的名稱,不必是自動命名的資料夾。
  3. 將本機 HD 資料夾的內容複製到 USB HD(第二份)。
  4. 清除CF卡。

我已經將我的旅行套件更新為 MacBook Air,而不是我之前使用的 Windows 系統。在先前的設定中,我在步驟2 和3 中使用了robocopy 腳本。重新運行它只會同步更改的檔案。

我是 OSX 新手,我糟糕的研究技能可能使用“ditto”或“rsync”出現,並被告知要研究“carbon copy cloner”和“superduper”。

簡而言之,我想要一種簡單的方法將 CF 卡的內容複製到 Macbook Air,然後複製到外部 USB 驅動器以確保安全。

答案1

我通常使用 rsync 在我的腳本上執行 rsync -av /home/source/folder/here /Volumes/Disk1/destination/folder/here ,並使用 Lingon 進行調度。 Crontab 確實不適合我,但 Lingon 一直有效。我找到了 2.2 的免費 GPL 下載,它對我來說工作得很好,但你甚至可以直接從 Mac App Store 花 3 美元購買版本 3。請記住,所有網路磁碟機、連接的 USB/Firewire 磁碟機都位於 /Volumes 目錄中作為自己的資料夾。希望這可以幫助!

答案2

你應該嘗試的第一件事可能是。您也可以嘗試像這樣修改 shell 腳本。

#!/bin/bash

dir1=/Volumes/CF/Photos
[[ ! -e "$dir1" ]] && exit

dir2=~/"Pictures/Photos"
mkdir -p "$dir2"

i=1
date="$(date +%Y%m%d)"
target="$dir2/$date-D$(printf %02d $i)"
while [[ -e "$target" ]]; do
    ((++i))
    target="$dir2/$date-D$(printf %02d $i)"
done

mkdir "$target"
mv "$dir1" "$target"
echo "Moved $dir1/ to $target/"

dir3="/Volumes/Backup/Photos"
[[ ! -e "$dir3" ]] && exit
rsync -a "$dir2" "$dir3"
echo "Copied $dir2/ to $dir3/"

要在安裝 CF 磁碟區(或修改其中的某些文件)時運行它,您可以保存像這樣的屬性列表,~/Library/LaunchAgents/com.superuser.411351.plist並使用launchctl load ~/Library/LaunchAgents/com.superuser.411351.plist.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN
http://www.apple.com/DTDs/PropertyList-1.0.dtd>
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.superuser.411351</string>
    <key>Program</key>
    <string>/usr/bin/copyphotos</string>
    <key>WatchPaths</key>
    <array>
        <string>/Volumes/CF/</string>
    </array>
</dict>
</plist>

相關內容