Note that there are some explanatory texts on larger screens.

plurals
  1. POShell script suddently stopped working
    primarykey
    data
    text
    <p>I found the following script online which makes backup of a database and uploads it to the S3 bucket:</p> <pre><code>#!/bin/bash # Shell script to backup MySql database # CONFIG - Only edit the below lines to setup the script # =============================== MyUSER="test" # USERNAME MyPASS="test" # PASSWORD MyHOST="localhost" # Hostname S3Bucket="test" # S3 Bucket # DO NOT BACKUP these databases IGNORE="information_schema mysql performance_schema phpmyadmin" # DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING # =============================== # Linux bin paths, change this if it can not be autodetected via which command MYSQL="$(which mysql)" MYSQLDUMP="$(which mysqldump)" CHOWN="$(which chown)" CHMOD="$(which chmod)" GZIP="$(which gzip)" # Backup Dest directory, change this if you have someother location DEST="/var/www/test/backup" # Main directory where backup will be stored MBD="$DEST/mysql-$(date +"%d-%m-%Y")" # Get hostname HOST="$(hostname)" # Get data in dd-mm-yyyy format NOW="$(date +"%d-%m-%Y")" # File to store current backup file FILE="" # Store list of databases DBS="" [ ! -d $MBD ] &amp;&amp; mkdir -p $MBD || : # Get all database list first if [ "$MyPASS" == "" ]; then DBS="$($MYSQL -u $MyUSER -h $MyHOST -Bse 'show databases')" else DBS="$($MYSQL -u $MyUSER -h $MyHOST -p$MyPASS -Bse 'show databases')" fi for db in $DBS do skipdb=-1 if [ "$IGNORE" != "" ]; then for i in $IGNORE do [ "$db" == "$i" ] &amp;&amp; skipdb=1 || : done fi if [ "$skipdb" == "-1" ] ; then FILE="$MBD/$db.$HOST.$NOW.gz" # dump database to file and gzip if [ "$MyPASS" == "" ]; then $MYSQLDUMP -u $MyUSER -h $MyHOST $db | $GZIP -9 &gt; $FILE else $MYSQLDUMP -u $MyUSER -h $MyHOST -p$MyPASS $db | $GZIP -9 &gt; $FILE fi fi done # copy mysql backup directory to S3 s3cmd sync -rv --skip-existing $MBD s3://$S3Bucket/ </code></pre> <p>So, I added a cron job to run it and ran it manually the first time, everything was OK and the backup appeared in S3 bucket. But, starting from today, when I try to run it manually, I get dozens of errors:</p> <pre><code>/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 </code></pre> <p>Its like not accepting the list of databases nor the credentials for the mysql. And I havent touched those. What could be the reason for this? I tried uploading the script again, the same exact script, running it with regular user, <code>sudo sh ./backup.sh</code> but all without success. Im using a Ubuntu on Amazon EC2, so maybe something with permissions is causing this? (I set it as exectutabe <code>sudo chmod +x backup.sh</code>, tried with chown 777 but all without success.</p> <p>Im not a shell scripting expert so this is confusing for me, I know my way around terminal but can't figure out why is this happening when the script wasn't altered at all.</p> <p>Cron command is: <code>0 10 * * * /var/www/magicpin/backup/backup.sh</code> (with <code>sudo crontab -e</code>), maybe I should use <code>crontab -e</code> and change the cron to <code>0 10 * * * sudo sh /var/www/magicpin/backup/backup.sh</code></p> <p>Thanks in advance!</p> <p>EDIT: Just to clarify why the script worked the first time. It appears the original script (which I later modified a bit, had a line which changed the permission on the directory). So, when I ran it first time, I could do it via ./backup.sh, from user Ubuntu. Next time, because the permissions were changed, that got me "permission denied", so thats when I started experimenting with <code>sh</code> and permissions and stuff.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload