假設用 linux crontab + tar 排程備份網站資料

# tar -zcpBf /home/backup/site1.tgz /var/www/html/site1/

備份出來的檔案會包含完整的路徑
var/www/html/site1/index.php
var/www/html/site1/robots.txt
var/www/html/site1/hello.jpg

但如果只想保留相對路徑,移除完整路徑
可改用以下參數
# tar -zcpBf /home/backup/site1.tgz -C /var/www/html/ site1/
site1/index.php
site1/robots.txt
site1/hello.jpg

tar -C 參數,先 cd 到該路徑,再執行備份指令
-C, --directory=DIR
Change to DIR before performing any operations.  This option is order-sensitive, i.e. it affects all options that follow.
 

arrow
arrow
    文章標籤
    linux tar
    全站熱搜
    創作者介紹
    創作者 helloworld 的頭像
    helloworld

    Hello World

    helloworld 發表在 痞客邦 留言(0) 人氣()