2015-05-10 16 views
0

我有一個運行在有線網絡上的Linux(Ubuntu 14.04)的Thinkpad和一個在另一個子網上無線運行Yosemite的Mac。他們都是工作機器。我還有一個1TB加密的USB外置聯想磁盤。我已經創建了以下腳本從Thinkpad的cron運行,以便將/ home/greg中的隱藏文件夾與外部驅動器(連接到TP)同步,並將其安裝到右側目錄。然後它應該同步/ home/greg的其餘非隱藏內容,並可能選擇/ etc的自定義部分。一旦完成,它應該爲Mac執行類似的操作,將隱藏的文件分開,但將內容聯合起來。我的第一個rsync只包含/ home/greg中的隱藏文件(。* /),第二個rsync旨在抓取那些不在該目錄中隱藏的內容。以下是正在進行的一項工作。cron腳本中的各種rsync命令來同步Ubuntu和Mac主目錄

#!/bin/bash 
#source 
LOCALHOME="/home/greg/" 

#target disk 
DRIVEBYIDPATH="/dev/disk/by-id" 
DRIVEID="disk ID here" 
DRIVE=$DRIVEBYIDPATH/$DRIVEID 

#mounted target directories 
DRIVEMOUNTPOINT="/media/Secure-BU-drive" 
THINKPADHIDDENFILES="/TPdot" 
MACHIDDENFILES="/MACdot" 
BACKUPDIR="/homeBU" 

#if test -a $DRIVE ;then echo "-a $?";fi 

# Check to see if the drive is showing up in /dev/disk/by-id 
function drivePresent { 
    if test -e $DRIVE 
    then echo "$DRIVE IS PRESENT!" 
     driveMounted 
    else 
     echo "$DRIVE is NOT PRESENT!" 
    fi 
} 

# Check to see if drive is mounted where expected by rsync and if not mount it 
function driveMounted { 
    mountpoint -q $DRIVEMOUNTPOINT 
    if [[ $? == 0 ]] 
    then 
     syncLocal #make sure local has completed before remote starts 
#temp disabled syncRemote 
    else 
     echo "drive $DRIVEID is PRESENT but NOT MOUNTED. Mounting $DRIVE on $DRIVEMOUNTPOINT" 
     mount $DRIVE $DRIVEMOUNTPOINT 
     if [ $? == 0 ] 
     then 
      driveMounted 
      #could add a counter + while/if to limit the retries to say 5? 
     fi # check mount worked, then re-test until true, at which point the test will follow the other path 
    fi 
} 

# Archive THINKPAD to USB encrypted drive 
function syncLocal { 
    echo "drive $DRIVEID is PRESENT and MOUNTED on $DRIVEMOUNTPOINT- now do rsync" 
    #rsync for all the Linux application specific files (hidden directories) 
    rsync -ar --delete --update $LOCALHOME/.* $DRIVEMOUNTPOINT/$BACKUPDIR/$THINKPADHIDDENFILES 
    #rsync for all the content (non-hidden directories) 
    rsync -ar --delete --exclude-from ./excludeFromRsync.txt $LOCALHOME $DRIVEMOUNTPOINT/$BACKUPDIR 
    #rsync for Linux /etc dir (includes some custom scripts and cron jobs) 
    #rsync 
} 

# Sync MAC to USB encrypted drive 
function syncRemote { # Sync Mac to USB encrypted drive 
    echo "drive $DRIVEID is PRESENT and MOUNTED on $DRIVEMOUNTPOINT- now do rsync" 
    #rsync for all the Mac application specific files (hidden directories) 
    rsync -h --progress --stats -r -tgo -p -l -D --update /home/greg/ /media/Secure-BU-drive/ 
    #rsync for all the content (non-hidden directories) 
    rsync -av --delete --exclude-from ./excludeFromRsync.txt $LOCALHOME $DRIVEMOUNTPOINT/$BACKUPDIR 
    #rsync for Mac /etc dir (includes some custom scripts and cron jobs) 
    rsync 
} 

#This is the program starting 
drivePresent 

在syncLocal第二rsync的提及排除文件的內容是(NB syncRemote是暫時停用):

.cache/ 
/Downloads/ 
.macromedia/ 
.kde/cache-North/ 
.kde/socket-North/ 
.kde/tmp-North/ 
.recently-used 
.local/share/trash 
**/*tmp*/ 
**/*cache*/ 
**/*Cache*/ 
**~ 
/mnt/*/** 
/media/*/** 
**/lost+found*/ 
/var/** 
/proc/** 
/dev/** 
/sys/** 
**/*Trash*/ 
**/*trash*/ 
**/.gvfs/ 
/Documents/RTC* 
.* 

我的問題是,的意思的第一個本地的rsync是僅捕獲/home/greg/.*文件似乎捕獲了一切或可能失敗的靜默並允許第二個本地rsync運行,但不排除/home/greg/.*文件? 我知道我已經添加了一個可能不相關的上下文的負載,但我認爲這可能有助於設置我對相關rsyncs的期望。對不起,如果我已經過度了。

在此先感謝 格雷格

回答

0

你必須要非常小心.*因爲它會在...拉。所以這是你的第一個rsync的行:

rsync -ar --delete --update $LOCALHOME/.* $DRIVEMOUNTPOINT/$BACKUPDIR/$THINKPADHIDDENFILES 

外殼擴展*等的rsync看到...,它會去全遞歸那兩個!

我不知道這是否有幫助:--exclude . --exclude ..嗯,我相信你知道使用-vn來幫助你調試rsync問題。

相關問題