Nice touch about the credentials, the way I did it in my scripts is not recommended, security-wise.
I noticed a couple of things:
1. In your first script for backing up the database, you've set the backup folder as:
Code:
BACKUP_DIR="/home/backup"
Currently, the script immediately transfers the database dump via SCP in SQL format.
2. In the second script, you're including /var/backupdb which isn't used in your case:
Code:
# Define the folders and files to be included in the backup
folders_and_files=(
"/var/www"
"/var/backupdb/*_${current_date}.sql" )
Subsequently, it transfers to your backup destination again. To streamline, I suggest connecting once via SCP and transferring a single complete archive for backup.
You can achieve this by simply changing the database backup directory to the one that is included in the final backup (/var/backupdb) and also removing the SCP process from the first script.
PS. When setting the cronjob, make sure to run the database backup script earlier than the second script