當檔案到達時,bash 腳本將惰性 tar 發送至 fifo

當檔案到達時,bash 腳本將惰性 tar 發送至 fifo

這是假設的場景:我有一個歸檔過程,其中顯示檔案並將它們附加到 tar,然後 tar 被壓縮。像這樣的東西:

while sleep 1 ; do
    new_files="$(some-command-to-scan-for files)"
    tar --append --file xxx.tar $new_files
    if [ condition ] ; then break; fi
done

cat xxx.tar | gzip | dd of=/another/directory/xxx-$(date).tgz
rm xxx.tar

我真正想要發生的是隨著循環的進行創建和壓縮 tar,這樣就不需要臨時檔案。當您附加時這是不可能的,因為您需要開啟現有文件並尋求結束。這是我真正想要的「草圖」:

while sleep 1 ; do
    new_files="$(some-command-to-scan-for files)"
    tar --append --file - $new_files
    if [ condition ] ; then break; fi
done | gzip | dd of=/another/directory/xxx-$(date).tgz

當 tar 轉到標準輸出時,是否有某種方法可以將更多檔案附加到 tar 中?

相關內容