cleanupHMCDB.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/sh
  2. #
  3. #
  4. # Licensed to the Apache Software Foundation (ASF) under one
  5. # or more contributor license agreements. See the NOTICE file
  6. # distributed with this work for additional information
  7. # regarding copyright ownership. The ASF licenses this file
  8. # to you under the Apache License, Version 2.0 (the
  9. # "License"); you may not use this file except in compliance
  10. # with the License. You may obtain a copy of the License at
  11. #
  12. # http://www.apache.org/licenses/LICENSE-2.0
  13. #
  14. # Unless required by applicable law or agreed to in writing,
  15. # software distributed under the License is distributed on an
  16. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17. # KIND, either express or implied. See the License for the
  18. # specific language governing permissions and limitations
  19. # under the License.
  20. #
  21. #
  22. dbFile="/var/db/hmc/data/data.db"
  23. if [[ "x" != "x$1" ]]; then
  24. dbFile=$1
  25. fi
  26. if [[ ! -f ${dbFile} ]]; then
  27. echo "DB file ${dbFile} does not exist";
  28. exit 1
  29. fi
  30. while true; do
  31. read -p "Are you really sure you want to wipe out the DB at ${dbFile}? (y/n)" yn
  32. case $yn in
  33. [Yy]* ) break;;
  34. [Nn]* ) echo "User aborted script. Exiting without cleaning up DB"; exit 0;;
  35. * ) echo "Please answer y or n.";;
  36. esac
  37. done
  38. echo "Deleting data from DB ${dbFile}, restoring to clean state"
  39. sqlite3 ${dbFile} "Delete FROM Clusters;"
  40. sqlite3 ${dbFile} "DELETE FROM ServiceInfo;"
  41. sqlite3 ${dbFile} "DELETE FROM ServiceComponentInfo;"
  42. sqlite3 ${dbFile} "DELETE FROM ServiceConfig;"
  43. sqlite3 ${dbFile} "DELETE FROM Hosts;"
  44. sqlite3 ${dbFile} "DELETE FROM HostRoles;"
  45. sqlite3 ${dbFile} "DELETE FROM HostRoleConfig;"
  46. sqlite3 ${dbFile} "DELETE FROM ConfigHistory;"
  47. sqlite3 ${dbFile} "DELETE FROM TransactionStatus;"
  48. sqlite3 ${dbFile} "DELETE FROM SubTransactionStatus;"
  49. exit 0;