910_initiate_doc_version_recovery 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/bash
  2. set -euo pipefail
  3. source /etc/container_environment.sh
  4. source /etc/overleaf/env.sh
  5. LOG_FILE=/var/lib/overleaf/data/history/doc-version-recovery.log
  6. export DOC_VERSION_RECOVERY_RESYNCS_NEEDED_FILE=/var/lib/overleaf/data/history/doc-version-recovery-resyncs.log
  7. echo "Checking for doc version recovery. This can take a while if needed. Logs are in $LOG_FILE"
  8. cd /overleaf/services/history-v1
  9. LOG_LEVEL=info node storage/scripts/recover_doc_versions.js 2>&1 | tee -a "$LOG_FILE"
  10. function resyncAllProjectsInBackground() {
  11. waitForService docstore 3016
  12. waitForService document-updater 3003
  13. waitForService filestore 3009
  14. waitForService history-v1 3100
  15. waitForService project-history 3054
  16. waitForService web-api 4000
  17. # Resync files that had their versions updated
  18. while read -r project_id; do
  19. echo "Resyncing project $project_id..."
  20. curl -X POST --silent "http://127.0.0.1:3054/project/$project_id/resync?force=true"
  21. done < "$DOC_VERSION_RECOVERY_RESYNCS_NEEDED_FILE"
  22. # Resync files that have broken histories
  23. /overleaf/bin/force-history-resyncs
  24. echo "Finished resyncing history for all projects. Adding .done suffix to log file"
  25. mv "$DOC_VERSION_RECOVERY_RESYNCS_NEEDED_FILE" "$DOC_VERSION_RECOVERY_RESYNCS_NEEDED_FILE.done"
  26. }
  27. function waitForService() {
  28. local name=$1
  29. local port=$2
  30. while ! curl --fail --silent "http://127.0.0.1:$port/status"; do
  31. echo "Waiting for $name service to start up"
  32. sleep 10
  33. done
  34. }
  35. if [ -f "$DOC_VERSION_RECOVERY_RESYNCS_NEEDED_FILE" ]; then
  36. echo "Finished recovery of doc versions. Resyncing history for all projects in the background."
  37. resyncAllProjectsInBackground &
  38. else
  39. echo "No recovery of doc versions needed."
  40. fi