1

is there a way to use tar to pack a directory and check the source data for changes after taring?

Well I want to pack a folder. But it can happen that the content of the folder is changed during the packing process. I need a way for tar to check if the source files have changed after the archive has been created. If so, the packed files should be overwritten with the new source files

2
  • 1
    Do this and this answer your question ? You can update the tar archive after you've created it . It's much simpler. Jun 9, 2020 at 7:16
  • yesss, this could work thank you
    – Rudi
    Jun 9, 2020 at 8:10

2 Answers 2

1

If you want to update just the contents of the existing files and also newer files (but not deleting the files from the archive which are no longer in the current directory ,because that will give you the error No such file or directory trying to update the archive ) , you can use the diff feature as @Niels Tolstrup mentioned and then use --update or simply -u to update the archive contents :

tar -uf tarfile.tar `tar --diff --file tarfile.tar | awk ' { print $1 } ' | cut -d: -f1`

Note : Tar update will make many duplicate entries in the tar file which you can see them via tar --list --file tarfile.tar but that's not a problem when you extract the files.

7
  • thats nice, is there a way or a hack to do that with compressed archives?
    – Rudi
    Jun 12, 2020 at 10:02
  • @Rudi For zip files it's quite straightforward .For xz and gzip files you have to first gunzip or unxz them ( which might be not suitable for you because you mentioned you have not enough disk space available) , then update the contents using the above method and finally recompress them. Jun 12, 2020 at 10:48
  • zip sounds an alternative, but if i try to append file to an exist zip, zip repack the whole archive. That mean, zip need disk space for two archives in zip process
    – Rudi
    Jun 12, 2020 at 11:58
  • @Rudi So what about gzip or xz ? Do they have the same problem ? Jun 12, 2020 at 11:59
  • i cant append files to an compressed tgz :( but i need it compressed. xz I have not yet examined, i will do it
    – Rudi
    Jun 12, 2020 at 12:03
1

you could rsync the directory to a temporary place, then you keep checking with rsync until there are no changes, and finally you make your tar file.

3
  • unfortunately I do not have enough disk space available, so it is important for me to update the archive by myself
    – Rudi
    Jun 9, 2020 at 7:21
  • 1
    tar has a diff option, have you tried it. Jun 9, 2020 at 7:32
  • @Parsa Mousavi wrote that i should use the -u option. i believe that could work for my case
    – Rudi
    Jun 9, 2020 at 8:12

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.