2

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

NETFLOX
  • 123

2 Answers2

2

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.

2

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.