Glam Prestige Journal

Bright entertainment trends with youth appeal.

I want to create a shell script to automatically backup MySQL DB. I will later copy it to an s3 bucket.

I have created the following shell script:

#vim /home/ubuntu/backup/mysqlbackup.sh
#!/bin/bash
## Specify the name of the database that you want to backupbackup
# Database credentials
USER="user1"
PASSWORD="password"
HOST="hostname.compute.amazonaws.com"
DB_NAME="db1"
#Backup_Directory_Locations
BACKUPROOT="/home/ubuntu/backup"
TSTAMP=$(date +"%d-%b-%Y-%H-%M-%S")
S3BUCKET="s3://s3bucket"
#LOG_FILE="/home/ubuntu/backup/log/dump.log"
mysqldump -h <HOST> -u <USER> --database <DB_NAME> -p"$PASSWORD" > $BACKUPROOT/$DB_NAME-$TSTAMP.sql

Then from the command line, I run the script:

sudo bash -x ./mysqlbackup.sh

And it fails, telling me:

HOST: No such file or directory

enter image description here

1 Answer

<HOST>. <DB_NAME> etc, are just placeholders.

They should be replaced by actual strings or shell variable expansions "$HOST", "$DB_NAME" and so on - just as you have done with -p"$PASSWORD"

The error message is because < and > are redirection operators.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy