user3776781
user3776781

Reputation: 31

Backup file folder in correct way

My situation is I only have execute permission from some folder:

Lets say, I would like to backup entire folder and exclude some folder and files with exclude.txt

Here is path I would like to backup:

/pdf/data/pdfnew/2014

And I only have permission to execute from this folder (main):

/pdf/data/pdfnew/2014/public/main

I put exclude.txt in same folder which I can execute the command (main)

I execute this command in (main folder):

tar -cjvf -X exclude.txt 2014.tar.bz2 /pdf/data/pdfnew/2014

The result is it still included folder that I dont want to backup.

Is there a correct way doing this?

Upvotes: 1

Views: 156

Answers (1)

Giacomo1968
Giacomo1968

Reputation: 26056

Do you have a user/home directory on that server? You should, so you should just place exclude.txt in your user/homedirectory on that server & run it like this from that directory:

tar -cjvf -X ~/exclude.txt ~/2014.tar.bz2 /pdf/data/pdfnew/2014

The ~/ is a shorthand for your user/home directory so in this case it is explicitly stating, “Read exclude.txt from the user/home directory & write ~/2014.tar.bz2 to the user/home directory.

But you also ask this:

Is there a correct way doing this?

There is never one canonical best way of doing something like this. It is all based on your final/end goal. Nothing more. Nothing less. That said, if I were you I would do it like this instead using the -C option:

tar -cjvf -X ~/exclude.txt ~/2014.tar.bz2 -C /pdf/data/pdfnew/ 2014

The uppercase -C option allows tar to internally change the working directory to /pdf/data/pdfnew/ so you can then create an archive of 2014 without having to have the whole directory tree retained in the backup. I find this is easier to work with because many times I want to backup the contents of a directory but have no use to retain the parent structure. That way the archive is more like a traditional ZIP archive which I find is easer to understand & work with.

Upvotes: 1

Related Questions