Curl command with date appended in filename for elastic search snapshot creation

0

I am using below command to create snapshot with date appended to the filename but getting error as invalid snapshot name and it must be lowercase.

#!/bin/bash
SNAPSHOT=`date +%Y%m%d-%H%M%S`
curl -XPUT "localhost:9200/_snapshot/my_backup/$SNAPSHOT?wait_for_completion=true"

Sony Anuja

Posted 2019-07-31T11:54:08.993

Reputation: 9

What must be lowercase? How can we guess what a valid URL looks like? Do you have documentation for the server you are connecting to? – tripleee – 2019-07-31T12:04:43.960

Looks like you are probably trying to use Elastic Search; if correct, please [edit] the question to add the relevant tags as well as a prose description in a sentence or two explaining the service or API you are trying to access and what you hope for the outcome to be.

– tripleee – 2019-07-31T12:07:05.360

But indeed, your private shell variables should be lower case. Is that what you mean? That's hardly something you need human help with? – tripleee – 2019-07-31T12:08:18.943

Answers

1

You can use the following:

#!/bin/sh

filename=snapshot
current_time=$(date "+%Y.%m.%d-%H.%M.%S")

filename_ts=$file_name.$current_time

curl -L -o $(filename_ts) "localhost:9200/_snapshot/my_backup/$filename_ts?wait_for_completion=true"

IMADJamil

Posted 2019-07-31T11:54:08.993

Reputation: 111

I was about to suggest the use of $(date "<format>") too as you need to fetch/evaluate at run time from the date command – Smock – 2019-07-31T12:32:30.407

The OP is already using that, only using the obsolescent backtick syntax instead of the modern $(...) command substitution syntax. – tripleee – 2019-07-31T12:36:03.267

0

If I am at all able to guess what you are asking, try this.

#!/bin/bash
now=$(date +%Y%m%d-%H%M%S)
curl -XPUT "localhost:9200/_snapshot/my_backup/snapshot_$now?wait_for_completion=true"

There are a few hygiene edits, but the beef is adding snapshot_ as a prefix of the snapshot name, to make sure it's not all-numeric.

tripleee

Posted 2019-07-31T11:54:08.993

Reputation: 2 480

No experience with this service, so this is just a guess as to what the error message means. Showing exactly what the error message looks like might be a useful update to your question if this doesn't solve it for you. – tripleee – 2019-07-31T12:11:49.063

Its not taking that value from now . I tried and the file created is snapshot_$now . I tried in lowercase as well like you suggested but still same thing. It should accept but not sure why . Even i am new to this command hence help :) – Sony Anuja – 2019-07-31T13:14:43.493

Then you have a typo somewhere or something; the shell will certainly replace $now in double quotes - with nothing if the variable is empty or unset. – tripleee – 2019-07-31T13:55:32.837

0

Thanks everyone for your help :) I am able to get the query resolved .

Below command worked :

curl -XPUT http://localhost:9200/_snapshot/IMS/"snapshot$(date +%d%m%y-%H%M%S)" and this created the output file as snapshot31072019-145244 .

Sony Anuja

Posted 2019-07-31T11:54:08.993

Reputation: 9