tar file with directory and single files

If none of the more specific forums is the right place to ask

tar file with directory and single files

Postby juliorollan » 2017-03-06 14:38

Hello. I'm stuck with the following issue. I made a backup script for Wordpress, which includes the installation directory and the database. They are stored in different paths.
At some point of the script, I create a tarball file including the directory and the sql flle with the command:

Code: Select all
tar -cf /path/to/archive.tar -C /path/to/wordpress/dir . /path/to/file.sql


The thing is that the Wordpress directory is archived under ./ in the tarball but the SQL file keeps its full path. I've been reading the tar manual, searched on the internet and tried several alternatives, but none seem to work.

I would like to concatenate, or append, the SQL file in the root of the tarball without the SQL's file full path.

Thanks in advance for your time.
juliorollan
 
Posts: 8
Joined: 2016-08-23 16:22
Location: Argentina

Re: tar file with directory and single files

Postby bw123 » 2017-03-06 17:42

I don't use tar much, kind of fun I guess, you want to do like this?

Code: Select all
$ ls path*
path1:
foo1.txt

path2:
foo2.txt

$ tar -cf archive.tar -C path1 . -C ../path2 foo2.txt

$ tar -tf archive.tar
./
./foo1.txt
foo2.txt
User avatar
bw123
 
Posts: 2378
Joined: 2011-05-09 06:02
Location: TN_USA

Re: tar file with directory and single files

Postby juliorollan » 2017-03-06 21:11

Closely, but path1 is a complete directory.
I use absolute paths because I don't know where the user is running the script in.
juliorollan
 
Posts: 8
Joined: 2016-08-23 16:22
Location: Argentina


Return to General Questions

Who is online

Users browsing this forum: No registered users and 7 guests

fashionable