you need to know the disk quota for that operation. Currently I don't have access to a linux system and I don't remember the exact command, but there may be some Quota modules on CPAN. And to calculate the approximate dump size, you have to calculate row lengths. I don't know how to get that value from command line, but this query will return the data:
SHOW TABLE STATUS FROM <DATABASE_NAME>;
this'll return a list with a lot of keys. "Data_length" is the one you are looking for. Here is a perl/DBI example:
use DBI;
my $dbname = "your_db_name";
my $dbh = DBI->connect('DBI:mysql:'.$dbname, 'root', '',{RaiseError => 1});
my $sth = $dbh->prepare("SHOW TABLE STATUS FROM $dbname");
$sth->execute;
my $size = 0;
while (my $stat = $sth->fetchrow_hashref) {
$size += $stat->{Data_length};
}
$dbh->disconnect;
printf "Total data size: %.2f KB", $size / 1024;
here $size gives you an approximate value, because a db dump will include more information than data and a lot of insert() etc statements... But it'll give you a value to compare:
$space = $quota - $disk_space_I_currently_use;
# $xtra can be a constant value for insert() statements
if ($space > $size+$xtra) {
# do backup
} else {
# don't
}