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 {} \;
I think you are just missing a -c on the gzip line, try: