-1

I wanted to tar some directory with gzip included. Please let me know what is the syntax for it. Following are also to be considered.

1) It would be helpful if the tar.gz is getting split after 2G is completed with one tar file.( say: tar.gzaa becomes 2G, then it should continue to create tar.gzab)

2) syntax for appending the log info into a log file

3) to exclude some type of files with particular extension ( say my source directory which is going to be tar is having some child dir with .log files and i need to exclude those to be get tarred.

Thanks in advance.

2
  • 1
    Hi. What have you tried so far? – Eduardo Baitello Mar 7 '17 at 2:09
  • The answer below satisfies your question? If yes, please accept it. If not, what else do you need? – Eduardo Baitello Mar 7 '17 at 20:13
2

Maybe you can try something like this:

tar --exclude='*.EXTENSION' -czvf - DIRECTORY/ 2> LOG_FILE.log | split --verbose --bytes=2048MB - FILE.tar.gz. >> LOG_FILE.log

Let's test. Assuming we have a directory named directory with this files:

eduardo@Notebook:~/testtar$ ll -h directory/
total 570M
drwxr-xr-x 2 eduardo eduardo 4,0K mar  6 23:25 ./
drwxr-xr-x 3 eduardo eduardo 4,0K mar  6 23:28 ../
-rw-r--r-- 1 eduardo eduardo    0 mar  6 23:16 file.any
-rw-r--r-- 1 eduardo eduardo 570M mar  6 23:24 hugefile.dd
-rw-r--r-- 1 eduardo eduardo    0 mar  6 23:15 image.jpg
-rw-r--r-- 1 eduardo eduardo    0 mar  6 23:16 log.log
-rw-r--r-- 1 eduardo eduardo    0 mar  6 23:14 text.txt

Tar command:

tar --exclude='*.log' -czvf - directory/ 2> splitted_tar.log | split --verbose --bytes=50MB - splitted_tar_file.tar.gz. >> splitted_tar.log

Output files:

eduardo@Notebook:~/testtar$ ll -h
total 299M
drwxr-xr-x  3 eduardo eduardo 4,0K mar  6 23:53 ./
drwxr-xr-x 41 eduardo eduardo 4,0K mar  6 23:16 ../
drwxr-xr-x  2 eduardo eduardo 4,0K mar  6 23:25 directory/
-rw-r--r--  1 eduardo eduardo  48M mar  6 23:52 splitted_tar_file.tar.gz.aa
-rw-r--r--  1 eduardo eduardo  48M mar  6 23:53 splitted_tar_file.tar.gz.ab
-rw-r--r--  1 eduardo eduardo  48M mar  6 23:53 splitted_tar_file.tar.gz.ac
-rw-r--r--  1 eduardo eduardo  48M mar  6 23:53 splitted_tar_file.tar.gz.ad
-rw-r--r--  1 eduardo eduardo  48M mar  6 23:53 splitted_tar_file.tar.gz.ae
-rw-r--r--  1 eduardo eduardo  48M mar  6 23:53 splitted_tar_file.tar.gz.af
-rw-r--r--  1 eduardo eduardo  13M mar  6 23:53 splitted_tar_file.tar.gz.ag
-rw-r--r--  1 eduardo eduardo  399 mar  6 23:53 splitted_tar.log

Log file:

eduardo@Notebook:~/testtar$ cat splitted_tar.log 
directory/
directory/text.txt
directory/hugefile.dd
directory/file.any
directory/image.jpg
creating file 'splitted_tar_file.tar.gz.aa'
creating file 'splitted_tar_file.tar.gz.ab'
creating file 'splitted_tar_file.tar.gz.ac'
creating file 'splitted_tar_file.tar.gz.ad'
creating file 'splitted_tar_file.tar.gz.ae'
creating file 'splitted_tar_file.tar.gz.af'
creating file 'splitted_tar_file.tar.gz.ag'

Notes:

  • The file log.log is not include in the final .tar.gz file due the parameter --exclude (make sure to put it before the source and destination items)
  • Tar verbose output goes to STDERR, this is why I used 2> LOG_FILE.log
  • Split verbose output goes to STDOUT, I just appended it with >> LOG_FILE.log
  • To "restore" your directory (join, gunzip and untar), you can use:

     cat splitted_tar_file.tar.gz.a? | tar -xzvf -
    
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.