

It creates a tar archive by converting a. It's inside a backup shell script launched by a Cron, so I don't know well, which user runs it, what is the path and the current directory, so always writing absolute path is required for everything, and would prefer not changing current directory to avoid breaking something further in the script (because it doesn't only backup websites, but also databases, then send all that to FTP etc. The tar command, also known as a tape archive, is used to compress files and folders in Linux operating systems. Some do nothing, some others don't archive sub-directories anymore. Tar -cjf site1.bz2 -strip-components=3 /var/www/site1/īut none of them worked the way I want. So the list of files needs to be generated by the shell and if you need the filenames as stored in the archive to have no directory component, you need either for to remove it (some have a option for that), or simply to into that dir before generating the list of files. Tar -cjf site1.bz2 -C /var/www/site1/ /var/www/site1/

There are already many questions about tar and backuping in stackoverflow and at other places on the web, but most of them ask for dropping the entire sub-directory structure (flattening), or just add or remove the initial / in the names (I don't know what it changes exactly when extracting), but no more.Īfter having read some of the solutions found here and there as well as the manual, I tried : tar -cjf site1.bz2 -C. So, that when I extract, files are extracted in the current directory and I don't need to move extracted files afterwards, and so that sub-directory structures is preserved.

When I list the contents of the archive, I get: tar -tf site1.bz2īut I would like to remove the part /var/For the example above, I would like to have : tar -tf site1.bz2 I have the following command in the part of a backup shell script: tar -cjf site1.bz2 /var/www/site1/
