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?

1 Answer 1

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

3
  • dar sounds interesting, how would i run this command in dar?
    – Ran
    Commented Jul 14, 2011 at 16:09
  • how about using tar with --tape-length and -M ?
    – Ran
    Commented Jul 14, 2011 at 16:12
  • 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".
    – user89061
    Commented Jul 14, 2011 at 16:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .