perl <<'EOF'
my $database = 'db_placeholder';
my ( $user ) = split(/\_/, $database);
my @homes = qw(home home1 home2 home3);
my $home;
if ( ! -d "/var/lib/mysql/$database" ) {
    die "[!] Specified database not found.\n";
}
foreach my $partition (@homes) {
    if ( -d "/$partition/$user" ) {
            $home = $partition;
            last;
    }
}
print "[*] Home partition for $user found as $home\n";
my $checksize;
if ( -s "/var/cpanel/datastore/$user/mysql-db-usage") {
    open(my $DAT, '<', "/var/cpanel/datastore/$user/mysql-db-usage");
        while(<$DAT>) {
                if ( /^$database: ([0-9]+)$/ ) {
                    $checksize = $1;
                    last;
                }
        }
}
if ( ! $checksize ) {
    print "[*] Cached database size not found. Checking manually. This may take a minute...\n";
    chomp(my ($checksize) = split(/\s+/, `du -b /var/lib/mysql/$database`));
}
if ( $checksize >= 1073741824 ) {
    die "[!] Database exceeds size limit. Please dump manually.\n";
}
my $epoch = time();
print "[*] Dumping database to /$home/$user/$database-$epoch.sql. This will lock tables, possibly for a long time. This may adversely effect site performance.\n";
system("mysqldump $database > /$home/$user/$database-$epoch.sql");
if ( -s "/$home/$user/$database-$epoch.sql" ) {
    print "[*] Done.\n";
} else {
    die "[!] Dump appears to have failed. Please dump manually.\n";
}
EOF
