You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
slms/scripts/backup_project.bat

290 lines
9.8 KiB

@echo off
REM ============================================================================
REM SLMS Project Backup Script
REM Purpose: Create complete backup of project and configurations before restructure
REM ============================================================================
setlocal enabledelayedexpansion
echo ============================================================================
echo SLMS Project Backup Script
echo ============================================================================
echo.
REM Set backup directory with timestamp
set TIMESTAMP=%date:~0,4%%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%%time:~6,2%
set TIMESTAMP=%TIMESTAMP: =0%
set BACKUP_DIR=backup_%TIMESTAMP%
echo Creating backup directory: %BACKUP_DIR%
mkdir "%BACKUP_DIR%" 2>nul
REM ============================================================================
REM 1. Backup Project Files
REM ============================================================================
echo.
echo [1/3] Backing up project files...
echo ----------------------------------------
REM Create project backup subdirectory
mkdir "%BACKUP_DIR%\project" 2>nul
echo Copying project files (this may take a few minutes)...
xcopy /E /I /H /Y /EXCLUDE:backup_exclude.txt . "%BACKUP_DIR%\project" >nul 2>&1
if %ERRORLEVEL% EQU 0 (
echo [OK] Project files backed up successfully
) else (
echo [WARNING] Some files may not have been copied
)
REM ============================================================================
REM 2. Export Jenkins Configuration
REM ============================================================================
echo.
echo [2/3] Exporting Jenkins configuration...
echo ----------------------------------------
mkdir "%BACKUP_DIR%\jenkins" 2>nul
REM Export Jenkinsfile
if exist Jenkinsfile (
copy Jenkinsfile "%BACKUP_DIR%\jenkins\Jenkinsfile.backup" >nul
echo [OK] Jenkinsfile backed up
) else (
echo [WARNING] Jenkinsfile not found
)
REM Create Jenkins configuration export instructions
echo Creating Jenkins configuration export guide...
(
echo # Jenkins Configuration Export
echo.
echo ## Manual Steps Required:
echo.
echo 1. **Export Job Configuration:**
echo - Navigate to: http://localhost:8080/job/YOUR_JOB_NAME/config.xml
echo - Save the XML file to: %BACKUP_DIR%\jenkins\job-config.xml
echo.
echo 2. **Export Jenkins System Configuration:**
echo - Navigate to: http://localhost:8080/configure
echo - Or export via CLI: java -jar jenkins-cli.jar -s http://localhost:8080/ get-job YOUR_JOB_NAME
echo.
echo 3. **Export Credentials:**
echo - Navigate to: http://localhost:8080/credentials/
echo - Document credential IDs:
echo * gitea-credentials
echo * educoder-credentials
echo * sonarqube-token
echo.
echo 4. **Export Plugins List:**
echo - Navigate to: http://localhost:8080/pluginManager/installed
echo - Or use: java -jar jenkins-cli.jar -s http://localhost:8080/ list-plugins
echo.
echo ## Automated Backup:
echo.
echo If Jenkins CLI is available, run:
echo ```
echo java -jar jenkins-cli.jar -s http://localhost:8080/ get-job SLMS ^> job-config.xml
echo ```
echo.
echo Backup created: %date% %time%
) > "%BACKUP_DIR%\jenkins\JENKINS_EXPORT_GUIDE.md"
echo [OK] Jenkins export guide created
REM ============================================================================
REM 3. Export SonarQube Configuration
REM ============================================================================
echo.
echo [3/3] Exporting SonarQube configuration...
echo ----------------------------------------
mkdir "%BACKUP_DIR%\sonarqube" 2>nul
REM Backup sonar-project.properties
if exist sonar-project.properties (
copy sonar-project.properties "%BACKUP_DIR%\sonarqube\sonar-project.properties.backup" >nul
echo [OK] sonar-project.properties backed up
) else (
echo [WARNING] sonar-project.properties not found
)
REM Create SonarQube configuration export instructions
echo Creating SonarQube configuration export guide...
(
echo # SonarQube Configuration Export
echo.
echo ## Manual Steps Required:
echo.
echo 1. **Export Project Settings:**
echo - Navigate to: http://localhost:9000/dashboard?id=slms
echo - Go to Project Settings ^> General Settings
echo - Document all custom settings
echo.
echo 2. **Export Quality Gates:**
echo - Navigate to: http://localhost:9000/quality_gates
echo - Document quality gate configuration
echo.
echo 3. **Export Quality Profiles:**
echo - Navigate to: http://localhost:9000/profiles
echo - Document active quality profiles for Java
echo.
echo 4. **Export Webhooks:**
echo - Navigate to: http://localhost:9000/project/webhooks?id=slms
echo - Document webhook URLs and configurations
echo.
echo 5. **Current Project Key:** slms:slms or slms
echo - This will be changed to: slms
echo.
echo ## Automated Backup via API:
echo.
echo If you have SonarQube token, run:
echo ```
echo curl -u YOUR_TOKEN: http://localhost:9000/api/settings/values?component=slms ^> settings.json
echo curl -u YOUR_TOKEN: http://localhost:9000/api/qualitygates/show?name=YOUR_GATE ^> qualitygate.json
echo ```
echo.
echo Backup created: %date% %time%
) > "%BACKUP_DIR%\sonarqube\SONARQUBE_EXPORT_GUIDE.md"
echo [OK] SonarQube export guide created
REM ============================================================================
REM 4. Create Backup Summary
REM ============================================================================
echo.
echo Creating backup summary...
(
echo # SLMS Project Backup Summary
echo.
echo **Backup Date:** %date% %time%
echo **Backup Location:** %BACKUP_DIR%
echo.
echo ## Backup Contents:
echo.
echo ### 1. Project Files
echo - Location: %BACKUP_DIR%\project\
echo - Contents: Complete project source code, build files, and configurations
echo - Excluded: target/, build/, .gradle/, .git/ ^(see backup_exclude.txt^)
echo.
echo ### 2. Jenkins Configuration
echo - Location: %BACKUP_DIR%\jenkins\
echo - Contents:
echo * Jenkinsfile backup
echo * Jenkins export guide with manual steps
echo - **Action Required:** Follow JENKINS_EXPORT_GUIDE.md for complete backup
echo.
echo ### 3. SonarQube Configuration
echo - Location: %BACKUP_DIR%\sonarqube\
echo - Contents:
echo * sonar-project.properties backup
echo * SonarQube export guide with manual steps
echo - **Action Required:** Follow SONARQUBE_EXPORT_GUIDE.md for complete backup
echo.
echo ## Restoration Instructions:
echo.
echo To restore from this backup:
echo.
echo 1. **Restore Project Files:**
echo ```
echo xcopy /E /I /H /Y %BACKUP_DIR%\project\* .
echo ```
echo.
echo 2. **Restore Jenkins Configuration:**
echo - Import job configuration via Jenkins UI or CLI
echo - Recreate credentials with same IDs
echo - Restore Jenkinsfile to project root
echo.
echo 3. **Restore SonarQube Configuration:**
echo - Recreate project with key: slms:slms
echo - Apply quality gates and profiles
echo - Reconfigure webhooks
echo.
echo ## Next Steps:
echo.
echo 1. Review this backup summary
echo 2. Complete manual export steps in jenkins/ and sonarqube/ directories
echo 3. Verify backup completeness
echo 4. Proceed with repository restructure
echo.
echo ## Important Notes:
echo.
echo - Keep this backup until restructure is verified successful
echo - Store backup in a safe location outside the project directory
echo - Test restoration process if possible
echo.
) > "%BACKUP_DIR%\BACKUP_SUMMARY.md"
REM ============================================================================
REM 5. Create Backup Verification Checklist
REM ============================================================================
(
echo # Backup Verification Checklist
echo.
echo Use this checklist to verify backup completeness:
echo.
echo ## Project Files
echo - [ ] Source code backed up ^(src/, backend/, android/^)
echo - [ ] Build files backed up ^(pom.xml, build.gradle, settings.gradle^)
echo - [ ] Configuration files backed up ^(Jenkinsfile, sonar-project.properties^)
echo - [ ] Documentation backed up ^(docs/^)
echo - [ ] Scripts backed up ^(scripts/^)
echo.
echo ## Jenkins Configuration
echo - [ ] Jenkinsfile backed up
echo - [ ] Job configuration exported
echo - [ ] Credentials documented
echo - [ ] Plugin list documented
echo - [ ] Webhook configuration documented
echo.
echo ## SonarQube Configuration
echo - [ ] sonar-project.properties backed up
echo - [ ] Project settings documented
echo - [ ] Quality gates documented
echo - [ ] Quality profiles documented
echo - [ ] Webhooks documented
echo.
echo ## Verification Steps
echo - [ ] Backup directory created successfully
echo - [ ] All files copied without errors
echo - [ ] Backup size is reasonable ^(check disk space^)
echo - [ ] Manual export guides reviewed
echo - [ ] Backup location is safe and accessible
echo.
echo ## Sign-off
echo.
echo Backup verified by: _______________
echo Date: _______________
echo.
) > "%BACKUP_DIR%\VERIFICATION_CHECKLIST.md"
REM ============================================================================
REM Summary
REM ============================================================================
echo.
echo ============================================================================
echo Backup Complete!
echo ============================================================================
echo.
echo Backup Location: %BACKUP_DIR%
echo.
echo Files Created:
echo - %BACKUP_DIR%\project\ (Project files)
echo - %BACKUP_DIR%\jenkins\ (Jenkins configuration)
echo - %BACKUP_DIR%\sonarqube\ (SonarQube configuration)
echo - %BACKUP_DIR%\BACKUP_SUMMARY.md
echo - %BACKUP_DIR%\VERIFICATION_CHECKLIST.md
echo.
echo IMPORTANT: Complete manual export steps:
echo 1. Review: %BACKUP_DIR%\jenkins\JENKINS_EXPORT_GUIDE.md
echo 2. Review: %BACKUP_DIR%\sonarqube\SONARQUBE_EXPORT_GUIDE.md
echo 3. Complete: %BACKUP_DIR%\VERIFICATION_CHECKLIST.md
echo.
echo ============================================================================
endlocal
pause