# Linux – Tar – split files

compressionlinuxtar

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?

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).
$dar -c "$BACKUPNAME" -g "\$INPUTFILE.sql" -s300M -z