2
0

mongodb-migration-status 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #!/bin/bash
  2. # MongoDB Migration Status Script
  3. # Provides status information about the migration process
  4. # Source settings
  5. source $SNAP/bin/wekan-read-settings
  6. # Configuration
  7. MIGRATION_STATUS="${SNAP_COMMON}/mongodb-migration-status.json"
  8. MIGRATION_LOG="${SNAP_COMMON}/mongodb-migration-log.txt"
  9. REVERT_FILE="${SNAP_COMMON}/revert-mongodb-migration.txt"
  10. # Show migration status
  11. show_status() {
  12. if [ -f "$MIGRATION_STATUS" ]; then
  13. echo "=== MongoDB Migration Status ==="
  14. echo "Status: $(jq -r '.status' "$MIGRATION_STATUS" 2>/dev/null || echo "unknown")"
  15. echo "Progress: $(jq -r '.step' "$MIGRATION_STATUS" 2>/dev/null || echo "0")/$(jq -r '.total_steps' "$MIGRATION_STATUS" 2>/dev/null || echo "0") steps"
  16. echo "Percentage: $(jq -r '.percentage' "$MIGRATION_STATUS" 2>/dev/null || echo "0")%"
  17. echo "Current Step: $(jq -r '.description' "$MIGRATION_STATUS" 2>/dev/null || echo "Unknown")"
  18. echo "Last Updated: $(jq -r '.timestamp' "$MIGRATION_STATUS" 2>/dev/null || echo "Unknown")"
  19. echo ""
  20. if [ -f "$MIGRATION_LOG" ]; then
  21. echo "=== Recent Migration Log ==="
  22. tail -10 "$MIGRATION_LOG"
  23. fi
  24. else
  25. echo "No migration in progress or completed."
  26. fi
  27. }
  28. # Show migration log
  29. show_log() {
  30. if [ -f "$MIGRATION_LOG" ]; then
  31. echo "=== Full Migration Log ==="
  32. cat "$MIGRATION_LOG"
  33. else
  34. echo "No migration log found."
  35. fi
  36. }
  37. # Check if migration is needed
  38. check_needed() {
  39. if [ -d "${SNAP_COMMON}/wekan" ] && [ ! -f "${SNAP_COMMON}/mongodb-version-7" ]; then
  40. echo "Migration needed: MongoDB 3 data detected"
  41. return 0
  42. else
  43. echo "No migration needed"
  44. return 1
  45. fi
  46. }
  47. # Start migration
  48. start_migration() {
  49. if check_needed; then
  50. echo "Starting MongoDB migration..."
  51. $SNAP/bin/mongodb-migrate
  52. else
  53. echo "Migration not needed or already completed"
  54. fi
  55. }
  56. # Request revert
  57. request_revert() {
  58. echo "Requesting migration revert..."
  59. touch "$REVERT_FILE"
  60. echo "Revert requested. Restart Wekan to apply revert."
  61. }
  62. # Clear migration status
  63. clear_status() {
  64. echo "Clearing migration status..."
  65. rm -f "$MIGRATION_STATUS"
  66. rm -f "$MIGRATION_LOG"
  67. rm -f "$REVERT_FILE"
  68. echo "Migration status cleared."
  69. }
  70. # Show help
  71. show_help() {
  72. echo "MongoDB Migration Status Tool"
  73. echo ""
  74. echo "Usage: $0 [command]"
  75. echo ""
  76. echo "Commands:"
  77. echo " status - Show current migration status (default)"
  78. echo " log - Show full migration log"
  79. echo " check - Check if migration is needed"
  80. echo " start - Start migration if needed"
  81. echo " revert - Request migration revert"
  82. echo " clear - Clear migration status"
  83. echo " help - Show this help"
  84. echo ""
  85. }
  86. # Main execution
  87. case "${1:-status}" in
  88. "status")
  89. show_status
  90. ;;
  91. "log")
  92. show_log
  93. ;;
  94. "check")
  95. check_needed
  96. ;;
  97. "start")
  98. start_migration
  99. ;;
  100. "revert")
  101. request_revert
  102. ;;
  103. "clear")
  104. clear_status
  105. ;;
  106. "help"|"-h"|"--help")
  107. show_help
  108. ;;
  109. *)
  110. echo "Unknown command: $1"
  111. show_help
  112. exit 1
  113. ;;
  114. esac