0

I'm trying to get a small script to run smoothly, it's supposed to archive all subfolders under /docker/*. What I wan't is the script to exclude all folders that has a date (i e 20191010, 20180502 and so on) this is my tar line:

for dir in *
# loop trough folders and archive them
do tar --exclude='//([12]\d{3}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01]))' --warning=no-file-changed -cjf "$dir".tar.bz2 "$dir" # no trailing slash!
    # Move created archive into subfolder
    mv ${dir}.tar.bz{datefolder}
done

But what it does is first creates the daily fodler (201909xx), and then it includes that in the tarballs. What am I missing?

Clarification (folder structure):

~/docker
    20190915  <- this should be excluded
    composer
    watchdog

The rest of the subfolders should be archived, each in its on tarball. .tr.bz2

  • I don't follow the question. Please expand on the details a bit. – gary Sep 15 '19 at 18:26
  • Just trying to figure out how to exclude the daily created folder (for example 20190915) from the tarballs. If I have the following folder structure; <code>/docker /20190915 /composer /whatever /somethingelse</code> I want tar to exclude the datefolder . – b0red Sep 15 '19 at 18:33
  • Updated the original question – b0red Sep 15 '19 at 18:39
  • 1
    I'm not sure that's a valid glob (admittedly I'm not certain). tar accepts glob (man 7 glob) expressions, not regex. – gary Sep 15 '19 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.