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?
Your script:
'[' 0 -le 1 ']'
: A zero here means the the command to backup succeeded, and reads "less than or equal to". And yes those lines with a "+" are showing you the various steps in the execution process and that is because you used the-x
in the option in executing the bash script.Also as noted by desert the sudo and the "-le" option should be removed and changed to "-lt" respectively.