Auto backup DB

Who can help me? I want to make an automatic backup of my db. But when I type ./backup.sh into my terminal nothing happens. So I don't think the backup is being made? or do i have something wrong in my code? ps. I use windows Code: #!/bin/bash Databasegegevens DB_HOST="localhost" DB_USER="root" DB_PASSWORD="" DB_NAME="twt" Pad naar de back-updirectory BACKUP_DIR="/mnt/c/Users/mstep/Documents/BACKUP_Twt" Bestandsnaam voor de back-up (voeg de huidige datum toe aan de bestandsnaam) BACKUP_FILE="$BACKUPDIR/backup$(date +%Y%m%d%H%M%S).sql" Maak de back-up met mysqldump mysqldump --host=$DB_HOST --user=$DB_USER --password=$DB_PASSWORD $DB_NAME > $BACKUP_FILE echo "Database back-up is gemaakt: $BACKUP_FILE" 0 0 * * 0 /bin/bash /mnt/c/Users/mstep/Documents/TWT_ProjectDev/Twt/backup.sh >/dev/null 2>&1
5 Replies
Jochem
Jochem12mo ago
can you put it in a code block so there's no formatting? open and close with ``` and you say "terminal" but there's at least three on a windows machine if you have WSL installed. Is it in bash in WSL, in powershell, or in cmd?
Rianẍa
Rianẍa12mo ago
#!/bin/bash

# Databasegegevens
DB_HOST="localhost"
DB_USER="root"
DB_PASSWORD=""
DB_NAME="twt"

# Pad naar de back-updirectory
BACKUP_DIR="/mnt/c/Users/mstep/Documents/BACKUP_Twt"

# Bestandsnaam voor de back-up (voeg de huidige datum toe aan de bestandsnaam)
BACKUP_FILE="$BACKUP_DIR/backup_$(date +%Y%m%d%H%M%S).sql"

# Maak de back-up met mysqldump
mysqldump --host=$DB_HOST --user=$DB_USER --password=$DB_PASSWORD $DB_NAME > $BACKUP_FILE

echo "Database back-up is gemaakt: $BACKUP_FILE"

0 0 * * 0 /bin/bash /mnt/c/Users/mstep/Documents/TWT_ProjectDev/Twt/backup.sh >/dev/null 2>&1


#!/bin/bash

# Databasegegevens
DB_HOST="localhost"
DB_USER="root"
DB_PASSWORD=""
DB_NAME="twt"

# Pad naar de back-updirectory
BACKUP_DIR="/mnt/c/Users/mstep/Documents/BACKUP_Twt"

# Bestandsnaam voor de back-up (voeg de huidige datum toe aan de bestandsnaam)
BACKUP_FILE="$BACKUP_DIR/backup_$(date +%Y%m%d%H%M%S).sql"

# Maak de back-up met mysqldump
mysqldump --host=$DB_HOST --user=$DB_USER --password=$DB_PASSWORD $DB_NAME > $BACKUP_FILE

echo "Database back-up is gemaakt: $BACKUP_FILE"

0 0 * * 0 /bin/bash /mnt/c/Users/mstep/Documents/TWT_ProjectDev/Twt/backup.sh >/dev/null 2>&1


and cmd line
Jochem
Jochem12mo ago
that's a bash script, it won't work in cmd do you have WSL running? also, the last couple of lines are a crontab entry, that doesn't go in a script, you have to add that to a linux machine's (or WSL's) crontab and it'll run at midnight on sunday
Rianẍa
Rianẍa12mo ago
cmd.exe /c "C:\xampp\htdocs\TWT_ProjectDev\Twt\backup.sh" >NUL 2>&1
cmd.exe /c "C:\xampp\htdocs\TWT_ProjectDev\Twt\backup.sh" >NUL 2>&1
I added this now. Also the file name is now backup.ps1
Jochem
Jochem12mo ago
but the contents is still a bash script, and the last line is still a crontab line that won't do anything but produce a syntax error? you can't just take a PHP file and change the extension to .js and assume it'll work in nodejs all of a sudden, the same applies here do you run WSL on your windows machine at all?