I am trying to make a bash script to backup my sevrer, however it is creating empty tar archive and empty sql files and I don't know why. Can anyone see the problems here?
#!/bin/bash
SERVER_DIR="/var/www/vhosts/site.org"
DATE=$(date +"%d-%m-%Y")
BACKUP_DIR="/backups/$DATE"
NAME="full-$DATE"
MYSQLUSER="admin"
MYSQLPASS="pass"
MYSQLDUMP="$(which mysqldump)"
GZIP="$(which gzip)"
mkdir -p $BACKUP_DIR
tar -zcvf $BACKUP_DIR/$NAME.tar.gz $SERVER_DIR
$MYSQLDUMP -u $MYSQLUSER -p$MYSQLPASS --all-databases | $GZIP -9 > $BACKUP_DIR/$NAME.sql
find /backup/ -mtime +31 -exec rm -rf {} \;
set -xvat the top of your script to help debug it. This will print out each line that will be executed, and then the line with the various variable values filled in. That will help verify your assumptions. You should also test the status of various commands. For example, check$?after the tar command to make sure it executed correctly.