Tar - pre-checking before making the Tar file

Coming from this thread, just wondering if there is an option to check if the Tar of the files/directory will be without any file-errors without actually making the tar.

Scenario:
Let's say you have a directory of 20GB, but you don't have the space to make Tar file at the moment, and you want to check before you actually make Tar achieve file, that all the files in the directory can be Tarred, how would you achieve this ?

Thanks

Obviously during a tar operation you can get errors reading the files and errors writing the archive. The archive can be a disk file, a tape drive, or some other device. One output device is /dev/null which is a black hole to nowhere. If you send the archive to that you will still see any reading errors.

1 Like

Thanks, so making a tar of directory = 20GB and sending it to /dev/null would not require additional free space of 20GB

Correct.

sent from my HTC smartphone

1 Like

how about redirecting the output to a text file, that's also an option

root@clodb:/clodbvg>/opt/freeware/bin/tar cvf -  /oradata | gzip > /clodbvg/bkp_30MAY16.tgz

re-directing the output to a file test.txt, so how would I do that for the above command ?

Here is one way:

( /opt/freeware/bin/tar cvf -  /oradata | gzip > /clodbvg/bkp_30MAY16.tgz ) > test.txt 2>&1
1 Like

If you want to see the output on screen but also capture it then you can have the best of both worlds using the 'tee' command:

<whatever command> | tee <output text capture file>
1 Like

I have tried this one, but does not work

root@clodb:/clodbvg>df -g
Filesystem    GB blocks      Free %Used    Iused %Iused Mounted on

/dev/fslv02       14.00      1.72   88%   160138    29% /oratech

root@clodb:/clodbvg>/opt/freeware/bin/tar -cvf -  /oratech | gzip > /clodbvg/bkp_21MAY16_oratech.tgz | tee output.txt

root@clodb:/clodbvg>ls -ltra
total 6956360
drwxr-xr-x    2 root     system          256 May 22 00:46 lost+found

-rw-r--r--    1 root     system            0 Jun 11 23:42 output.txt
drwxr-xr-x    5 root     system         4096 Jun 11 23:42 .
-rw-r--r--    1 root     system   1054146560 Jun 11 23:45 bkp_21MAY16_oratech.tgz

root@clodb:/clodbvg>cat output.txt
root@clodb:/clodbvg>



output.txt is 0KB and there is nothing in it.

Whereas this

root@clodb:/clodbvg>(/opt/freeware/bin/tar -cvf -  /oratech | gzip > /clodbvg/bkp_21MAY16_oratech.tgz) > testoutput.txt 2>&1


root@clodb:/clodbvg>ls -ltra
total 5760048
drwxr-xr-x    2 root     system          256 May 22 00:46 lost+found

-rw-r--r--    1 root     system         1324 Jun 11 23:47 testoutput.txt


root@clodb:/clodbvg>cat testoutput.txt
/opt/freeware/bin/tar: Removing leading `/' from member names
/oratech/
/oratech/.TTauthority
/oratech/.Xauthority
/oratech/.dt/
/oratech/.dt/Desktop/
/oratech/.dt/Trash/
/oratech/.dt/Trash/.trashinfo
/oratech/.dt/appmanager/
/oratech/.dt/errorlog
/oratech/.dt/help/
/oratech/.dt/help/oraprod-oradb-0/
/oratech/.dt/help/oraprod-oradb-0/browser.hv
/oratech/.dt/help/oraprod-oradb-0/browser00.ht
/oratech/.dt/help/oraprod-oradb-0/browser01.ht

works perfectly.

Where's your backup file gone with the second version?

The first trial with tee fails because the files' names are listed to stderr, which doesn't make it into tee , and which you redirect in version 2. Still, you don't have the files on screen AND in testoutput as desired.

1 Like

With my GNU bash, version 4.3.42(1)-release (x86_64-pc-linux-gnu), i came up with

tar cvf - fi* 2> >(tee ZZ /dev/tty) | gzip > XX 
file
file~
file1
file1~
file2
file2~
cat ZZ
file
file~
file1
file1~
file2
file2~

which seems to be close to what you requested.

1 Like

With the second version, I will not see any output on the screen , it will be redirected to the file.

root@clodb:/clodbvg>ls -ltra
total 16417272
drwxr-xr-x    2 root     system          256 May 22 00:46 lost+found

-rw-r--r--    1 root     system     12976636 Jun 12 00:28 testoutput.txt
-rw-r--r--    1 root     system   5885143569 Jun 12 00:28 bkp_21MAY16_oratech.tgz

root@clodb:/clodbvg>tail -n3 testoutput.txt | more
/opt/freeware/bin/tar: Removing leading `/' from member names
/oratech/
/oratech/.TTauthority
/oratech/.Xauthority
/oratech/.dt/
/oratech/.dt/Desktop/
/oratech/.dt/Trash/
/oratech/.dt/Trash/.trashinfo
/oratech/.dt/appmanager/
/oratech/.dt/errorlog
/oratech/.dt/help/
/oratech/.dt/help/oraprod-oradb-0/
/oratech/.dt/help/oraprod-oradb-0/browser.hv
/oratech/.dt/help/oraprod-oradb-0/browser00.ht
/oratech/.dt/help/oraprod-oradb-0/browser01.ht

root@clodb:/clodbvg>tail -n3 testoutput.txt
/oratech/smit.script
/oratech/smit.transaction
/oratech/test1

now trying with your version

root@clodb:/clodbvg>bash
root@clodb:/clodbvg>tar cvf - /oratech 2> >(tee ZZ /dev/tty) | gzip > testversion.tgz
a /oratech
a /oratech/.TTauthority 1 blocks.
a /oratech/.Xauthority 1 blocks.
a /oratech/.dt
a /oratech/.dt/Desktop
a /oratech/.dt/Trash
a /oratech/.dt/Trash/.trashinfo 0 blocks.
a /oratech/.dt/appmanager
a /oratech/.dt/errorlog 1 blocks.
a /oratech/.dt/help
a /oratech/.dt/help/oraprod-oradb-0
a /oratech/.dt/help/oraprod-oradb-0/browser.hv 2 blocks.



root@clodb:/clodbvg>cat ZZ
a /oratech
a /oratech/.TTauthority 1 blocks.
a /oratech/.Xauthority 1 blocks.
a /oratech/.dt
a /oratech/.dt/Desktop
a /oratech/.dt/Trash
a /oratech/.dt/Trash/.trashinfo 0 blocks.
a /oratech/.dt/appmanager
a /oratech/.dt/errorlog 1 blocks.
a /oratech/.dt/help
a /oratech/.dt/help/oraprod-oradb-0
a /oratech/.dt/help/oraprod-oradb-0/browser.hv 2 blocks.
a /oratech/.dt/help/oraprod-oradb-0/browser00.ht 3 blocks.
a /oratech/.dt/help/oraprod-oradb-0/browser01.ht 0 blocks.


Now trying the files which had error

root@clodb:/clodbvg>tar cvf - /oradata/proddata/applsys*.* 2> >(tee errorfiles.txt /dev/tty) | gzip > errorfiles.tgz
a /oradata/proddata/applsysd01.dbf 6963216 blocks.
a /oradata/proddata/applsysd02.dbf 14680080 blocks.
/oradata/proddata/applsysd02.dbf: There is an input or output error.
tar: 0511-182 Read error on a /oradata/proddata/applsysd03.dbf 13107216 blocks.
a /oradata/proddata/applsysd04.dbf 4505616 blocks.
a /oradata/proddata/applsysd05.dbf 4505616 blocks.
a /oradata/proddata/applsysx01.dbf 4915216 blocks.
a /oradata/proddata/applsysx02.dbf 7987216 blocks.

The error is only on applsysd02.dbf and not applsysd03.dbf

root@clodb:/clodbvg>/opt/freeware/bin/tar cvf -  /oradata | gzip > /clodbvg/bkp_30MAY16.tgz 

/opt/freeware/bin/tar: Removing leading `/' from member names
/oradata/
/oradata/JAVA/
/oradata/JAVA/.toc
/oradata/JAVA/Java131.rte
/oradata/JAVA/Java131.rte.tar
/oradata/Stage11i/
/oradata/lost+found/
/oradata/proddata/
/oradata/proddata/XDOD.dbf
/oradata/proddata/XDOX.dbf
/opt/freeware/bin/tar: /oradata/proddata/applsysd02.dbf: Read error at byte 4767080960, reading 10240 bytes: There is an input or output error.
/oradata/proddata/applsysd03.dbf
/oradata/proddata/applsysd04.dbf
/oradata/proddata/applsysd05.dbf
/oradata/proddata/applsysx01.dbf
/oradata/proddata/applsysx02.dbf

Thanks Rudic.

Rudic, for restore how would you do it ?

Backup

tar cvf - fi* 2> >(tee ZZ /dev/tty) | gzip > XX 

Restore

. 

Sort of (untested)

gunzip XX | tar xf -

Doesn't your tar version offer the -z option for creation and extraction of gzip ped archives?

---------------------

I'm inclined to bet there's <CR> chars involved.

sorry for misunderstanding, meant to say restore using tee command to capture the output like how wrote the command for backup..
so where to put

tee

command in your code

gunzip XX | tar xf -

Try (untested):

gunzip XX | tar xf - 2>&1 | tee ZZ 
1 Like