LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Help Using The Tar Command (https://www.linuxquestions.org/questions/linux-newbie-8/help-using-the-tar-command-4175484447/)

gaspower 11-13-2013 10:04 AM

Help Using The Tar Command
 
Hello,

Need a little help with the Tar command. Just need to make sure what I have listed below is going to do what I need.

tar -pcvjf backups/tarbackupname.$DATETIME.tar.bz2 html/ > /dev/null 2>&1

Directory structure

/home/virtual/site1/var/www/html/(all the web files and directories)

I would like to tar all files and folders from the html directory and down. Also want to keep the file permissions, which I think is the -p?

Where I get lost, if I want to tar all files and folders under html/, do I run the command in the html folder, or one above in the www folder. Also, which ever folder I do run the command, I would like the tar file to be created in that folder where it is executed.

Thanks JR

grail 11-13-2013 10:23 AM

Quote:

Also want to keep the file permissions, which I think is the -p?
This would seem to be a correct assumption based on the man page entry.
Quote:

if I want to tar all files and folders under html/, do I run the command in the html folder, or one above in the www folder.
You can run tar from anywhere, the difference being that where you are will then change how much of the path to the location you need to enter.
So with your current example, because you use 'html/' you would need to be in the directory directly above as this is a relative path as opposed to an absolute one
which starts at root (/) down to location.
Quote:

Also, which ever folder I do run the command, I would like the tar file to be created in that folder where it is executed.
If that is the case then why do you place the backups directory name in front of the tar file name? Remember that tar will not create a directory (that I know of)

Madhu Desai 11-13-2013 01:50 PM

@gaspower

You can run tar command from anywhere you like as long as path at where you want to save tar file and path of which you want to take backup are correct. Just keep in mind that when you want to restore (untar) them, where do you want to put those files (the one you backed-up)... does matter.

Generally, when you want take backup of system files, and you want to restore them at the place where they originally belonged, then tar them with absolute path.
Other than this, if you want to take backup of files/folders and want to restore them in which-ever folder you like, then tar them with relative path.

please refer http://www.linuxquestions.org/questi...2/#post4997953

Original Source: Beginning the Linux Command Line - Sander van Vugt. Page 57.


All times are GMT -5. The time now is 08:50 AM.