tar
2010/7/16 17:58:34
- 僅備份比某個時刻還要新的檔案
某些情況下你會想要備份新的檔案而已,並不想要備份舊檔案!此時 --newer-mtime 這個選項就粉重要啦! 其實有兩個選項啦,一個是『 --newer 』另一個就是『 --newer-mtime 』,這兩個選項有何不同呢? 我們在 第七章的 touch 介紹中談到過三種不同的時間參數, 當使用 --newer 時,表示後續的日期包含『 mtime 與 ctime 』,而 --newer-mtime 則僅是 mtime 而已! 這樣知道了吧! ^_^ 。那就讓我們來嘗試處理一下囉!
# 1. 先由 find 找出比 /etc/passwd 還要新的檔案 [root@www ~]# find /etc -newer /etc/passwd ....(過程省略).... # 此時會顯示出比 /etc/passwd 這個檔案的 mtime 還要新的檔名, # 這個結果在每部主機都不相同!您先自行查閱自己的主機即可,不會跟鳥哥一樣! [root@www ~]# ll /etc/passwd -rw-r--r-- 1 root root 1945 Sep 29 02:21 /etc/passwd # 2. 好了,那麼使用 tar 來進行打包吧!日期為上面看到的 2008/09/29 [root@www ~]# tar -jcv -f /root/etc.newer.then.passwd.tar.bz2 / > --newer-mtime="2008/09/29" /etc/* ....(中間省略).... /etc/smartd.conf <==真的有備份的檔案 ....(中間省略).... /etc/yum.repos.d/ <==目錄都會被記錄下來! tar: /etc/yum.repos.d/CentOS-Base.repo: file is unchanged; not dumped # 最後行顯示的是『沒有被備份的』,亦即 not dumped 的意思! # 3. 顯示出檔案即可 [root@www ~]# tar -jtv -f /root/etc.newer.then.passwd.tar.bz2 | / > grep -v '/$' # 透過這個指令可以呼叫出 tar.bz2 內的結尾非 / 的檔名!就是我們要的啦! |