PDA

View Full Version : tar seperate gzip/tar files into one tar file with one command



pharubu
August 27th, 2013, 03:14 AM
I'm running out of room on the drives and can no longer do separate
tar/gzip files before combining all gzip/tar files into one tar file.

Is it possible to pipe a separate gzip/tar straight into a combined tar file ?

Currently:
#!/bin/sh
fsFilePath="/var/backups/"
fsFileName="WWWBackup.tar.gz"
fsFileLoc="${fsFilePath}${fsFileName}"
pg_dump --blobs DB1 | gzip -c > ${fsFilePath}DB1Dump.out.gz
pg_dump --blobs DB2 | gzip -c > ${fsFilePath}DB2Dump.out.gz
pg_dump --blobs DB3 | gzip -c > ${fsFilePath}DB3Dump.out.gz

tar -czpf ${fsFilePath}www.tar.gz -C / var/www
tar -czpf ${fsFilePath}apache2.tar.gz -C / etc/apache2

fsFilePathRemoveFirstFwdSlash=`echo ${fsFilePath} | sed 's/^.//'`
cd /
tar -czpf ${fsFileLoc} ${fsFilePathRemoveFirstFwdSlash}*
cd ${fsFilePath}

ls ${fsFilePath}* | grep -v ${fsFileLoc} | xargs rm -f

To something like:
pg_dump --blobs DB1 | gzip -c DB1Dump.out.gz | tar -czpf combined.tar
pg_dump --blobs DB2 | gzip -c DB2Dump.out.gz | tar -uzpf combined.tar
pg_dump --blobs DB3 | gzip -c DB3Dump.out.gz | tar -uzpf combined.tar

tar -czpf ${fsFilePath}www.tar.gz -C / var/www | tar -uzpf combined.tar
tar -czpf ${fsFilePath}apache2.tar.gz -C / etc/apache2 | tar -uzpf combined.tar

Thanks

evilsoup
August 27th, 2013, 09:56 AM
What's the advantage to doing this rather than just putting all the files in a tarball and compressing that (which could be done with a single tar command)?

Bucky Ball
August 27th, 2013, 10:11 AM
Thread moved to Programming Talk.

You have more chance of getting help here. Unsure why this was originally posted in ABS.

ofnuts
August 27th, 2013, 10:30 AM
Use tar --append?

http://www.gnu.org/software/tar/manual/html_node/append.html#SEC58

pharubu
August 28th, 2013, 01:50 AM
The best way to describe what I was trying to do is to think of it like a bag full of bite sized mini bars.
I didnt want to warp up the bite sized treats first and then individually put them in the bag.
I wanted to wrap the bite sized snacks inside the bag itself thereby saving space on the harddrive.

What I have done is to:
- Dump/gzip all the small DB's and website directories into their own bite sized tar files.
- tar the bite sized tar files into the one combined tar file.
- Remove the mini tar files
- Do a gzip/dump of the big database
- Add it to the combined tar file
- Remove the big DB tar file

It will work for now however i'd like to know if its possible to wrap files into a tar and put them straight into a combined tar.

ofnuts
August 29th, 2013, 12:54 PM
Use "tar -- concatenate"?