I am using the following script to create a database backup and sending it to a storage location using scp.What I noticed is that the resulting file very frequently delivers a seemingly correct file. For the most of the time, the file size is around the 3GiB mark, but sometimes the resulting file is some 900B, sometimes 2.2MiB.The script is:#!/bin/bash# database credentialsDATABASEHOST=<host>DATABASEUSER=<user>DATABASEPASSWORD=<password>DATABASESCHEMA=<schema>DATABASEENV=<env># Local directory of mysqldump fileLOCALDIR=<localdir># Temporary directory for compressed fileTEMPDIR=<tempdir># Remote Directory for backups.REMOTEDIR=<remote-dir># USERname to login asBACKUPUSER=<backupuser># Backup host to login toBACKUPHOST=<backuphost># mysqldump fileMYSQLDUMPFILE=$(date +%Y%m%d)_bkp_$DATABASESCHEMA.sql# compressed fileCOMPRESSEDFILE=$(date +%Y%m%d)_$DATABASEENV_$DATABASESCHEMA.tar.gz#--- end configecho $(date +%H:%M)echo Creating the MySQL dump mysqldump --host=$DATABASEHOST --user=$DATABASEUSER --password=$DATABASEPASSWORD --single-transaction $DATABASESCHEMA > $LOCALDIR/$MYSQLDUMPFILE#echo Generating md5summd5sum $LOCALDIR/* > $LOCALDIR/checklist.chk#echo Compressing the dump and checklisttar -cvzf $TEMPDIR/$(date +%Y%m%d)_$DATABASEENV_$DATABASESCHEMA.tar.gz $LOCALDIR/*#echo Sending the compressed file to storage locationscp $TEMPDIR/$COMPRESSEDFILE $BACKUPHOST:$REMOTEDIRecho Removing generated filesrm $LOCALDIR/checklist.chk > /dev/null 2>&1rm $LOCALDIR/$MYSQLDUMPFILE > /dev/null 2>&1rm $TEMPDIR/$COMPRESSEDFILE > /dev/null 2>&1echo $(date +%H:%M)Since most of the times the resulting file is ok, I'm thinking the problem may rely on the scp part.How can I ensure the storage location generated file is the same as the original and, if they're different, try to scp again? 
database backup script generating file of different sizes?
backup;scp
use rsync please. Rsync checks md5 hash of file.rsync examples