@@ -121,13 +121,13 @@ function create_readonly_mysql_user() {
echo" +-- password: (provided on the command line)"
# otherwise, create a random one
else
RUSER_PW="$( pwgen -s 24 1 )"||( display_error "Error generating password; is pwgen installed and in \$PATH?"&&return 1)
RUSER_PW="$( pwgen -s 24 1 )"||{ display_error "Error generating password; is pwgen installed and in \$PATH?";return 1;}
echo" +-- password: $RUSER_PW"
fi
# do the magic
mysql -h"$1"-u"$2"--password="$3"--batch-e"GRANT SELECT, SHOW DATABASES, LOCK TABLES, EXECUTE, SHOW VIEW ON *.* TO '$RUSER_NAME'@'$RUSER_HOST' IDENTIFIED BY '$RUSER_PW';"\
||( display_error "Error creating a read-only user."&&return 1)
||{ display_error "Error creating a read-only user.";return 1;}
}
export-f create_readonly_mysql_user
...
...
@@ -167,7 +167,7 @@ function dump_mysql_dbs {
DATABASES="$( mysql -h"$1"-u"$2"--password="$3"--batch-e"SHOW DATABASES $DATABASES_WHERE;" | egrep -v'(Database|information_schema|performance_schema)')"
# either the code is 0, or the command failed; act accordingly.
[$?-eq 0 ]||( display_error&&return 1)
[$?-eq 0 ]||{ display_error;return 1;}
# did we find anything?
if[["$DATABASES"==""]];then
...
...
@@ -202,7 +202,7 @@ function dump_mysql_dbs {
# get the list of users
DBUSERS="$( mysql -h"$1"-u"$2"--password="$3"--batch--skip-column-names-e"SELECT CONCAT('',QUOTE(user),'@',QUOTE(host),':',$PWCOL) FROM mysql.user WHERE user<>'';")"
# get the grants # add IDENTIFIED BY <password>, but only when there was no IDENTIFIED BY there already
DBGRANTS=`echo-ne"$DBGRANTS\n$( mysql -h"$1"-u"$2"--password="$3"--batch--skip-column-names-e"SHOW GRANTS FOR $DBUSER;" | sed-r-e"s/(IDENTIFIED BY.*)$/ IDENTIFIED BY PASSWORD '$DBUSERPW'/g")"`
[$?-eq 0 ]||( display_error&&return 4)
[$?-eq 0 ]||{ display_error;return 4;}
done
# iterate through databases
...
...
@@ -312,11 +312,11 @@ function create_readonly_postgres_user() {
echo" +-- found `echo"$DBUSERS" | egrep "^CREATE" | wc-l` users..."
...
...
@@ -529,17 +529,17 @@ function dump_elasticsearch_dbs {
# create a snapshot, blocking until it's done
echo" +-- dump..."
curl -X PUT "http://$1:9200/_snapshot/$BACKUP_NAME/snapshot?wait_for_completion=true"||( display_error 'Error while generating the snapshot!'&&return 1)
curl -X PUT "http://$1:9200/_snapshot/$BACKUP_NAME/snapshot?wait_for_completion=true"||{ display_error 'Error while generating the snapshot!';return 1;}
echo
# copy the backup to a less temporary location
cp-a"$BACKUP_TEMP_DIR"/*"$2/"||( display_error 'Error while copying the snapshot data to the target directory!'&&return 2)
cp-a"$BACKUP_TEMP_DIR"/*"$2/"||{ display_error 'Error while copying the snapshot data to the target directory!';return 2;}
# cleanup
echo" +-- cleanup..."
curl -X DELETE "http://$1:9200/_snapshot/$BACKUP_NAME/snapshot"||( display_error 'Error while cleaning up the snapshot!'&&return 3)
curl -X DELETE "http://$1:9200/_snapshot/$BACKUP_NAME/snapshot"||{ display_error 'Error while cleaning up the snapshot!';return 3;}
echo
curl -X DELETE "http://$1:9200/_snapshot/$BACKUP_NAME/"||( display_error 'Error while cleaning up the backup repository!'&&return 4)
curl -X DELETE "http://$1:9200/_snapshot/$BACKUP_NAME/"||{ display_error 'Error while cleaning up the backup repository!';return 4;}
echo
rm-rf"$BACKUP_TEMP_DIR/*"
echo" +-- done..."
...
...
@@ -563,8 +563,8 @@ function ssh_rsa_encrypt {
["$1"!=""]&&PUBKEY="$1"
# reality checks -- does the file exist, is it a file, is it readable
[-e"$PUBKEY"]||(>&2 display_error "The specified SSH RSA public key '$PUBKEY' does not exist."&&return 1)
[-r"$PUBKEY"]||(>&2 display_error "The specified SSH RSA public key '$PUBKEY' is not readable to this user."&&return 2)
[-e"$PUBKEY"]||{>&2 display_error "The specified SSH RSA public key '$PUBKEY' does not exist.";return 1;}
[-r"$PUBKEY"]||{>&2 display_error "The specified SSH RSA public key '$PUBKEY' is not readable to this user.";return 2;}
# temporary file for the pubkey in OpenSSL-compatible PEM format
PUBKEY_PEM="$(mktemp)"
...
...
@@ -598,8 +598,8 @@ function ssh_rsa_decrypt {
["$1"!=""]&&PRIVKEY="$1"
# reality checks -- does the file exist, is it a file, is it readable
[-e"$PRIVKEY"]||(>&2 display_error "The specified SSH RSA public key '$PRIVKEY' does not exist."&&return 1)
[-r"$PRIVKEY"]||(>&2 display_error "The specified SSH RSA public key '$PRIVKEY' is not readable to this user."&&return 2)
[-e"$PRIVKEY"]||{>&2 display_error "The specified SSH RSA public key '$PRIVKEY' does not exist.";return 1;}
[-r"$PRIVKEY"]||{>&2 display_error "The specified SSH RSA public key '$PRIVKEY' is not readable to this user.";return 2;}