mysql - Shell script suddently stopped working -
i found following script online makes backup of database , uploads s3 bucket:
#!/bin/bash # shell script backup mysql database # config - edit below lines setup script # =============================== myuser="test" # username mypass="test" # password myhost="localhost" # hostname s3bucket="test" # s3 bucket # not backup these databases ignore="information_schema mysql performance_schema phpmyadmin" # not edit below line unless know doing # =============================== # linux bin paths, change if can not autodetected via command mysql="$(which mysql)" mysqldump="$(which mysqldump)" chown="$(which chown)" chmod="$(which chmod)" gzip="$(which gzip)" # backup dest directory, change if have someother location dest="/var/www/test/backup" # main directory backup stored mbd="$dest/mysql-$(date +"%d-%m-%y")" # hostname host="$(hostname)" # data in dd-mm-yyyy format now="$(date +"%d-%m-%y")" # file store current backup file file="" # store list of databases dbs="" [ ! -d $mbd ] && mkdir -p $mbd || : # database list first if [ "$mypass" == "" ]; dbs="$($mysql -u $myuser -h $myhost -bse 'show databases')" else dbs="$($mysql -u $myuser -h $myhost -p$mypass -bse 'show databases')" fi db in $dbs skipdb=-1 if [ "$ignore" != "" ]; in $ignore [ "$db" == "$i" ] && skipdb=1 || : done fi if [ "$skipdb" == "-1" ] ; file="$mbd/$db.$host.$now.gz" # dump database file , gzip if [ "$mypass" == "" ]; $mysqldump -u $myuser -h $myhost $db | $gzip -9 > $file else $mysqldump -u $myuser -h $myhost -p$mypass $db | $gzip -9 > $file fi fi done # copy mysql backup directory s3 s3cmd sync -rv --skip-existing $mbd s3://$s3bucket/
so, added cron job run , ran manually first time, ok , backup appeared in s3 bucket. but, starting today, when try run manually, dozens of errors:
/var/www/test/backup/backup.sh: 48: [: test: unexpected operator /var/www/test/backup/backup.sh: 62: [: information_schema: unexpected operator /var/www/test/backup/backup.sh: 62: [: information_schema: unexpected operator /var/www/test/backup/backup.sh: 62: [: information_schema: unexpected operator /var/www/test/backup/backup.sh: 62: [: information_schema: unexpected operator /var/www/test/backup/backup.sh: 62: [: information_schema: unexpected operator /var/www/test/backup/backup.sh: 66: [: -1: unexpected operator /var/www/test/backup/backup.sh: 62: [: mysql: unexpected operator /var/www/test/backup/backup.sh: 62: [: mysql: unexpected operator /var/www/test/backup/backup.sh: 62: [: mysql: unexpected operator /var/www/test/backup/backup.sh: 62: [: mysql: unexpected operator /var/www/test/backup/backup.sh: 62: [: mysql: unexpected operator /var/www/test/backup/backup.sh: 66: [: -1: unexpected operator
its not accepting list of databases nor credentials mysql. , havent touched those. reason this? tried uploading script again, same exact script, running regular user, sudo sh ./backup.sh
without success. im using ubuntu on amazon ec2, maybe permissions causing this? (i set exectutabe sudo chmod +x backup.sh
, tried chown 777 without success.
im not shell scripting expert confusing me, know way around terminal can't figure out why happening when script wasn't altered @ all.
cron command is: 0 10 * * * /var/www/magicpin/backup/backup.sh
(with sudo crontab -e
), maybe should use crontab -e
, change cron 0 10 * * * sudo sh /var/www/magicpin/backup/backup.sh
thanks in advance!
edit: clarify why script worked first time. appears original script (which later modified bit, had line changed permission on directory). so, when ran first time, via ./backup.sh, user ubuntu. next time, because permissions changed, got me "permission denied", thats when started experimenting sh
, permissions , stuff.
you're bash
script appears fine, believe way invoking it. sh
, bash
different shells. try running this:
sudo ./backup.sh
or
sudo bash ./backup.sh
instead of
sudo sh ./backup.sh
Comments
Post a Comment