Guest User

Untitled

a guest
Jun 20th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. curl -XPUT 'localhost:9200/_snapshot/my_backup/snapshot_2?wait_for_completion=true&pretty' -H 'Content-Type: application/json' -d'
  2. {
  3. "indices": "index_1,index_2",
  4. "ignore_unavailable": true,
  5. "include_global_state": false
  6. }'
  7.  
  8. #!/usr/bin/python
  9. # -*- coding: utf-8 -*-
  10. import json
  11. from collections import defaultdict
  12. import urllib2
  13. import requests
  14. from random import randrange
  15. from requests.auth import HTTPBasicAuth
  16. import sys
  17. import threading
  18. reload(sys)
  19. sys.setdefaultencoding("utf-8")
  20.  
  21. headers = {'Content-Type': 'application/json'}
  22. data = {"type": "fs", "settings": {"location": "/home/gnsarchlab/backup"}}
  23. tmpdict = defaultdict()
  24. tmpdict = json.dumps(data)
  25. method=""
  26.  
  27. def initialiseSnapshot():
  28.  
  29. response=requests.put('http://localhost:9200/_snapshot/my_backup?pretty',headers=headers,data = tmpdict)
  30. print response
  31. if(response.status_code != None and response.status_code == 200):
  32. print "Snapshot Initiated"
  33. print response.status_code
  34.  
  35. else:
  36. print "Error initialsing snapshot"
  37. print response.status_code
  38.  
  39.  
  40. def validatingRepository():
  41.  
  42. response=requests.get('http://localhost:9200/_snapshot/my_backup?pretty')
  43. print response
  44.  
  45. if(response.status_code != None and response.status_code == 200):
  46. print "Repository Validated"
  47. print response.status_code
  48.  
  49. else:
  50. print "Error validating repository"
  51. print response.status_code
  52.  
  53. def capturingSnapshot():
  54.  
  55. print "Enter 0 for taking snapshot of all the indices."
  56. print "Enter 1 to give the name of the indice"
  57. indice = int(raw_input())
  58. if indice == 0:
  59. response=requests.put('http://localhost:9200/_snapshot/my_backup/snapshot_1?wait_for_completion=true&pretty')
  60. print response
  61.  
  62. if(response.status_code != None and response.status_code == 200):
  63. print "Snapshot Captured"
  64.  
  65. else:
  66. print "Error capturing snapshot"
  67.  
  68. if indice == 1:
  69. indice_name = raw_input("Enter indice name: ")
  70. datadict = defaultdict()
  71. data1 = {"ignore_unavailable": "true", "include_global_state": "false"}
  72. data2 = defaultdict()
  73. data2['indices'] = indice_name
  74. print data2
  75. data1.append(data2)
  76. print data1
  77. datadict = json.dumps(data1)
  78. response1=requests.put('localhost:9200/_snapshot/my_backup/snapshot_2?wait_for_completion=true&pretty',data=datadict)
  79. print response
  80.  
  81. if(response.status_code != None and response.status_code == 200):
  82. print "Snapshot Captured"
  83.  
  84. else:
  85. print "Error capturing snapshot"
  86.  
  87.  
  88. if __name__ == "__main__":
  89.  
  90. if(len(sys.argv) < 2):
  91. print "Usage : python sdn.py [initialise|validate|capture|all]"
  92. elif(sys.argv[1] == "initialise"or sys.argv[1] == "is"):
  93. initialiseSnapshot()
  94. elif(sys.argv[1] == "validate" or sys.argv[1] == "vr"):
  95. validatingRepository()
  96. elif(sys.argv[1] == 'capture' or sys.argv[1] == "cs"):
  97. capturingSnapshot()
  98. elif(sys.argv[1] == 'all'):
  99. initialiseSnapshot()
  100. validatingRepository()
  101. capturingSnapshot()
  102.  
  103. if indice == 1:
  104. ...
  105. data1 = {"ignore_unavailable": "true", "include_global_state": "false"}
  106. data1.append(data2) # here
  107.  
  108. if indice == 1:
  109. ...
  110. data1 = {"ignore_unavailable": "true", "include_global_state": "false"}
  111. data1['datas'] = []
  112. data1['datas'].append(data2) # here
Add Comment
Please, Sign In to add comment