Tar - split files

4

i am using the following command to backup and sql file:

tar -zcvf "$BACKUP_DST/$FILE_NAME.tgz" "$BACKUP_DST/$FILE_NAME.sql"

i want to make sure the compressed file wont be larger then 300mb, if it exceeds 300mb, split it into several files.

any thoughts?

Ran

Posted 2011-07-14T15:36:08.700

Reputation: 257

Answers

8

I don't think tar has functionality built-in to split at an arbitrary size (there is -M for multi-volume, but this relies on the destination media detecting an out-of-space condition), but there are two things you could do:

  1. Generate a single tar.gz file in the usual way, then use the split command to divide it into sections (and cat to join them back together for decompression).
  2. Use dar instead of tar, since this has splitting functionality built in (amongst a lot of other features that tar doesn't have). For example

    $ dar -c "$BACKUPNAME" -g "$INPUTFILE.sql" -s300M -z

user89061

Posted 2011-07-14T15:36:08.700

Reputation:

dar sounds interesting, how would i run this command in dar? – Ran – 2011-07-14T16:09:17.350

how about using tar with --tape-length and -M ? – Ran – 2011-07-14T16:12:38.770

I added an example dar command. I just tested --tape-length and it doesn't work with compressed archives, repeatedly overwrites the same .tar file without changing the name, and requires you to hit ENTER after each "slice". – None – 2011-07-14T16:22:48.590