GitLab CI/CD: Create tar.gz with content inside current working dir and save tar.gz inside current working dir: tar: .: file changed as we read it
0
votes
1
answer
122
views
I'm trying to create an archive e.g.
https://xkcd.com/1168/ " class="img-fluid rounded" style="max-width: 100%; height: auto; margin: 10px 0;" loading="lazy">
archive.tar.gz
inside the current working directory e.g. /builds/project/
without saving the archive.tar.gz
inside archive.tar.gz
.
To prevent this I'm trying to use --exclude=PATTERN option.
This should be an easy task. But it's not.
Finally, I would like to name the archive after a set variable and exclude it.
Versions:
$ bash --version
GNU bash, version 5.2.15(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ tar --version
tar (GNU tar) 1.34
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later .
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by John Gilmore and Jay Fenlason.
I've tried multiple versions, with quotes, without, exclude at different positions, PATTERN with ./ and without and nothing works:
$ tar -czf --exclude=archive1.tar.gz archive1.tar.gz . || true
tar: archive1.tar.gz: Cannot stat: No such file or directory
tar: .: file changed as we read it
tar: Exiting with failure status due to previous errors
$ tar -czf --exclude="archive2.tar.gz" archive2.tar.gz . || true
tar: archive2.tar.gz: Cannot stat: No such file or directory
tar: .: file changed as we read it
tar: Exiting with failure status due to previous errors
$ tar -czf --exclude=./archive3.tar.gz archive3.tar.gz . || true
tar: archive3.tar.gz: Cannot stat: No such file or directory
tar (child): --exclude=./archive3.tar.gz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: --exclude=./archive3.tar.gz: Cannot write: Broken pipe
tar: Child returned status 2
tar: Error is not recoverable: exiting now
$ tar -czf --exclude="./archive4.tar.gz" archive4.tar.gz . || true
tar: archive4.tar.gz: Cannot stat: No such file or directory
tar (child): --exclude=./archive4.tar.gz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: --exclude=./archive4.tar.gz: Cannot write: Broken pipe
tar: Child returned status 2
tar: Error is not recoverable: exiting now
$ tar -czf archive5.tar.gz --exclude=archive5.tar.gz . || true
tar: .: file changed as we read it
$ tar -czf archive6.tar.gz --exclude="archive6.tar.gz" . || true
tar: .: file changed as we read it
$ tar -czf archive7.tar.gz --exclude=./archive7.tar.gz . || true
tar: .: file changed as we read it
$ tar -czf archive8.tar.gz --exclude="./archive8.tar.gz" . || true
tar: .: file changed as we read it
$ TAR_FILE=archive9.tar.gz ; tar -czf --exclude=$TAR_FILE $TAR_FILE . || true
tar: archive9.tar.gz: Cannot stat: No such file or directory
tar: .: file changed as we read it
tar: Exiting with failure status due to previous errors
$ TAR_FILE=archive10.tar.gz ; tar -czf --exclude="$TAR_FILE" $TAR_FILE . || true
tar: archive10.tar.gz: Cannot stat: No such file or directory
tar: .: file changed as we read it
tar: Exiting with failure status due to previous errors
$ TAR_FILE=archive11.tar.gz ; tar -czf --exclude=./$TAR_FILE $TAR_FILE . || true
tar: archive11.tar.gz: Cannot stat: No such file or directory
tar (child): --exclude=./archive11.tar.gz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: --exclude=./archive11.tar.gz: Cannot write: Broken pipe
tar: Child returned status 2
tar: Error is not recoverable: exiting now
$ TAR_FILE=archive12.tar.gz ; tar -czf --exclude="./$TAR_FILE" $TAR_FILE . || true
tar: archive12.tar.gz: Cannot stat: No such file or directory
tar (child): --exclude=./archive12.tar.gz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: --exclude=./archive12.tar.gz: Cannot write: Broken pipe
tar: Child returned status 2
tar: Error is not recoverable: exiting now
$ TAR_FILE=archive13.tar.gz ; tar -czf $TAR_FILE --exclude=$TAR_FILE . || true
tar: .: file changed as we read it
$ TAR_FILE=archive14.tar.gz ; tar -czf $TAR_FILE --exclude="$TAR_FILE" . || true
tar: .: file changed as we read it
$ TAR_FILE=archive15.tar.gz ; tar -czf $TAR_FILE --exclude=./$TAR_FILE . || true
tar: .: file changed as we read it
$ TAR_FILE=archive16.tar.gz ; tar -czf $TAR_FILE --exclude="./$TAR_FILE" . || true
tar: .: file changed as we read it
https://xkcd.com/1168/

Asked by rosaLux161
(41 rep)
Oct 23, 2024, 02:04 PM
Last activity: Oct 23, 2024, 03:17 PM
Last activity: Oct 23, 2024, 03:17 PM