There you go. Nothing too serious. Works fine from command line.
#!/bin/bash
###########################################################################
BACKUP_FILE=backup_CPSMS_`date +%d-%m-%y_%H%M`.tgz
BACKUP_PATH=/var/CPbackup/backups
BACKUP_COMMAND="/opt/CPsuite-R80.20/fw1/bin/upgrade_tools/migrate export -n"
BACKUP_SERVER='192.168.0.1'
BACKUP_USER='fwadmin'
BACKUP_PASS='********'
###########################################################################
echo `date +%d-%m-%yT%H%M` INFO: Backup script started
cd $BACKUP_PATH
source /etc/profile.d/CP.sh
# Run backup command
echo `date +%d-%m-%yT%H%M` "INFO: Running $BACKUP_COMMAND $BACKUP_FILE"
$BACKUP_COMMAND $BACKUP_FILE
if [ $? -ne 0 ]; then
echo `date +%d-%m-%yT%H%M` "FATAL: Backup command did not complete successfully"
exit 1
else
echo `date +%d-%m-%yT%H%M` "INFO: Backup command completed successfully"
fi
# Test backup file integrity
echo `date +%d-%m-%yT%H%M` "INFO: Testing archive integrity..."
/bin/tar -tzf $BACKUP_FILE > /dev/null
if [ $? -ne 0 ]; then
echo `date +%d-%m-%yT%H%M` "FATAL: Archive integrity test failed. Backup file is corrupt."
exit 1
else
echo `date +%d-%m-%yT%H%M` "INFO: Archive integrity test succeeded. Backup file is good."
echo `date +%d-%m-%yT%H%M` "INFO: Creating checksum file $BACKUP_FILE.MD5SUM"
/usr/bin/md5sum $BACKUP_FILE > $BACKUP_FILE.MD5SUM
echo `date +%d-%m-%yT%H%M` "INFO: Uploading archive to FTP server..."
ftp -n $BACKUP_SERVER <<END_SCRIPT
quote USER $BACKUP_USER
quote PASS $BACKUP_PASS
cd CPSMS
put $BACKUP_FILE.MD5SUM
binary
put $BACKUP_FILE
quit
END_SCRIPT
if [ $? -ne 0 ]; then
echo `date +%d-%m-%yT%H%M` "ERROR: FTP upload failed."
else
echo `date +%d-%m-%yT%H%M` "INFO: FTP upload completed."
fi
fi
echo `date +%d-%m-%yT%H%M` Removing backup file.
rm -f $BACKUP_FILE
rm -f $BACKUP_FILE.MD5SUM
echo `date +%d-%m-%yT%H%M` INFO: Backup script completed
# EOF