I've this script that creates a mysql dump of a database and sends it to a storage server. But I see that, sometimes, the generated files is of wrong size, even sending the file with rsync.I'd like to test the remote file for md5sum and if hash is the same, the local file is removed. If the hash is different, though, the rsync is re-attempted. The original 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 locationrsync -azvh $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)
how to make a loop with md5sum test on a bash script?
bash;shell script;hashsum
rsync knows when a file is incomplete.Just run rsync regularly, and it will by itself take care to re-send new parts of the file as needed.It could happen that $TEMPDIR is too small to contain the tar czvf ? then you would send that (incomplete) file with rsync?why not simplify:dump the DB as you didthen cd $LOCALDIR && rsync -azvh *_bkp_*.sql $BACKUPHOST:$REMOTEDIR