I have created the following shell scrip to backup MySQL DB, zip it, and then copy it to an s3 bucket:
#vim /home/ubuntu/backup/mysqlbackup2.sh
#!/bin/bash
## Backup mysql DB, zip it and then copy it to s3 bucket
mysqldump -hhostname -uusername dbName -p'p@ssW0rd' > db.sql
if [ $? -le 1 ]
then
# zip the file and copy it s3 bucket
sudo gzip -9 db.sql
s3cmd put db.sql.gz s://mys3bucket/
else
echo "Fail to backup MySQL DB" >> "backup.log"
fi
It does everything fine and the backup is copied to s3 bucket. But I cannot understand the output of shell script:
I understand the password warning but why does it show: '[' 0 -le 1 ']'
? Is there anything wrong in my if condition?
sudo
inside the script (and that’s actually not a good practice, see https://askubuntu.com/q/425754/507051) if you run the whole script as root. – dessert May 21 '19 at 04:57[ $? -eq 0 ]
and it's working. Thanks a lot. – Hooman Bahreini May 21 '19 at 06:05