gzip generating corrupt file on ubuntu 1604

I created a simple cron job to do daily backup of a database in the server, everything goes fine until the last step where I run the following command

gzip $ filename

gzip appears to be working fine but when you check the file size it is something impossibly small like a few kilobytes from a file that is close to a gigabyte in size, this happens most of the time but occasionally the file will be compressed correctly with a file size of about 198 MB

obviously when I try to gunzip the file it fails. This script runs fine on several other servers

Things I have tried:

I changed the command to gzip -k $ filename to keep the original file in case the gzip fails

I copied the original file from it’s current location to a home directory and made sure I have the right permissions on the folder and file, then I tried to compress the file myself and the same thing happens

I have more than enough storage space

Btw the file that I am trying to compress is an Oracle data pump file