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"
3
  • 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
    Jul 31, 2019 at 12:04
  • 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
    Jul 31, 2019 at 12:07
  • 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
    Jul 31, 2019 at 12:08

3 Answers 3

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"
2
  • 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
    Jul 31, 2019 at 12:32
  • The OP is already using that, only using the obsolescent backtick syntax instead of the modern $(...) command substitution syntax.
    – tripleee
    Jul 31, 2019 at 12:36
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.

3
  • 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
    Jul 31, 2019 at 12:11
  • 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
    Jul 31, 2019 at 13:14
  • 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
    Jul 31, 2019 at 13:55
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 .

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .