====== 複製資料 ====== rsync -avhW --no-compress --info=progress2 src/ dst/ rsyncd 設定檔 (server) rsyncd.conf pid file = /var/run/rsyncd.pid lock file = /var/run/rsync.lock log file = /var/log/rsync.log [nas] path = /shares/rsync/nas uid = root #gid = share gid = root read only = no list = yes auth users = root secrets file = /etc/rsyncd.secrets rsyncd.secrets root:PASSWORD 備份指令,在要備份資料的伺服器上執行,192.168.50.35 為 rsync server。 參數說明 * --delete delete extraneous files from destination dirs * --archive archive mode; equals -rlptgoD RSYNC_PASSWORD="PASSWORD" rsync --delete --archive /home root@192.168.50.35::nas 選項與參數: rsync [-avrlptgoD] [-e ssh] [user@host:/dir] [/local/path] * -v :觀察模式,可以列出更多的資訊,包括鏡像時的檔案檔名等; * -q :與 -v 相反,安靜模式,略過正常資訊,僅顯示錯誤訊息; * -r :遞迴複製!可以針對『目錄』來處理!很重要! * -u :僅更新 (update),若目標檔案較新,則保留新檔案不會覆蓋; * -l :複製連結檔的屬性,而非連結的目標原始檔案內容; * -p :複製時,連同屬性 (permission) 也保存不變! * -g :保存原始檔案的擁有群組; * -o :保存原始檔案的擁有人; * -D :保存原始檔案的裝置屬性 (device) * -t :保存原始檔案的時間參數; * -I :忽略更新時間 (mtime) 的屬性,檔案比對上會比較快速; * -z :在資料傳輸時,加上壓縮的參數! * -e :使用的通道協定,例如使用 ssh 通道,則 -e ssh * -a :相當於 -rlptgoD ,所以這個 -a 是最常用的參數了! Rsync over SSH 範例 rsync -a --progress --delete -e "ssh -i /home/user/.ssh/id_rsa" /home/CSNA2016/backup CSNA2016@backup.example.com:/home/user ====== 標題 ====== rsync -a --exclude 'file.txt' src_directory/ dst_directory/ rsync -a --exclude 'dir1' src_directory/ dst_directory/ rsync -a --exclude 'dir1/*' src_directory/ dst_directory/ rsync -a --exclude 'file1.txt' --exclude 'dir1/*' --exclude 'dir2' src_directory/ dst_directory/ rsync -a --exclude={'file1.txt','dir1/*','dir2'} src_directory/ dst_directory/ rsync -a --exclude-from='exclude-file.txt' src_directory/ dst_directory/ rsync -a --exclude '*.jpg*' src_directory/ dst_directory/ rsync -a -m --include='*.jpg' --include='*/' --exclude='*' src_directory/ dst_directory/ find src_directory/ -name "*.jpg" -printf %P\\0\\n | rsync -a --files-from=- src_directory/ dst_directory/ 參考 * http://newsletter.ascc.sinica.edu.tw/news/read_news.php?nid=1742 * http://blog.xuite.net/pippeng/blog/23403776 * https://www.myfreax.com/how-to-exclude-files-and-directories-with-rsync/