rem 设置运行脚本变量 :::: 压缩执行文件路径 set rar_exe="C:\Program Files\WinRAR\Rar.exe" :::: 文件压缩拆分大小 set file_size=49m :::: SQL自动备份文件夹路径,要带\ set sql_back_file_path=F:\BashTest\sqlfile\ ::::上传git仓库文件夹路径,要带\ set git_file_path=F:\BashTest\filename3\ ::::git拉取同步分支 set git_branck=master
:: 创建日志文件 set dir_path=%~dp0 set log_path=%dir_path%push_log.txt set now_time=%date:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,2%:%time:~3,2%:%time:~6,2%
echo %log_path% if not exist %log_path% ( echo"Backup Log">%log_path% )
rem 拉取最新代码 cd %git_file_path% if %errorlevel% neq 0 goto fail git reset --hard if %errorlevel% neq 0 goto fail git fetch --all if %errorlevel% neq 0 goto fail git pull origin %git_branck% ::if %errorlevel% neq 0 goto fail
:::: 删除obj文件 rem rd /s /q .git\objects rem if %errorlevel% neq 0 goto fail rem md .git\objects rem if %errorlevel% neq 0 goto fail rem rd /s /q .git/refs/original/ rem if %errorlevel% neq 0 goto fail rem git reflog expire --expire=now --all rem git gc --prune=now
rem rem 清除大文件 ::git filter-branch --index-filter"git rm --cached --ignore-unmatch *" -- --all git filter-branch --force --index-filter"git rm -r --cached --ignore-unmatch filefolder" --prune-empty --tag-name-filtercat -- --all rd /s /q .git\refs\original\ if %errorlevel% neq 0 goto fail rd /s /q .git\logs\ if %errorlevel% neq 0 goto fail git reflog expire --expire=now --all if %errorlevel% neq 0 goto fail git gc --prune=now --aggressive if %errorlevel% neq 0 goto fail git add . git commit -m"data clean" git push origin --force --all ::if %errorlevel% neq 0 goto fail rem rem 清空分支 rem git checkout %git_branck% rem if %errorlevel% neq 0 goto fail rem git checkout --orphan master-new-line; rem if %errorlevel% neq 0 goto fail rem git add -A rem if %errorlevel% neq 0 goto fail rem git commit -am"init project" rem if %errorlevel% neq 0 goto fail rem git branch -D %git_branck% rem if %errorlevel% neq 0 goto fail rem git branch -m %git_branck% rem if %errorlevel% neq 0 goto fail rem git push -f origin %git_branck%:%git_branck% rem if %errorlevel% neq 0 goto fail
rem git pack-refs --all --prune rem git reflog expire --all rem git repack -d-l rem git prune --expire rem git rerere gc
rem git checkout -b %git_branck% rem git fetch --all
rem 分卷压缩指定文件夹内文件 :started set now_day_format=%date:~0,4%_%date:~5,2%_%date:~8,2% %rar_exe% a -m5-v%file_size% -ta%now_day_format% -agYYYYMMDD %git_file_path%filefolder\ %sql_back_file_path% if %errorlevel% neq 0 goto fail
rem 提交gitee :gitpush cd %git_file_path% if %errorlevel% neq 0 goto fail git add . if %errorlevel% neq 0 goto fail git commit -m"daily backup" if %errorlevel% neq 0 goto fail git push origin %git_branck%:%git_branck% if %errorlevel% neq 0 goto fail
rem rem 上传完毕,清空仓库 rem :dellocal rem del filefolder\*.rar goto success
::::下载git仓库文件夹路径,要带\ set git_file_path=F:\BashTest\filename3\ ::::本地存储文件夹路径,要带\ set storage_file_path=F:\BashTest\filename2\ ::::git拉取同步分支 set git_branck=file
:: 创建日志文件 set dir_path=%~dp0 set log_path=%dir_path%pull_log.txt set now_time=%date:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,2%:%time:~3,2%:%time:~6,2%
echo %log_path% if not exist %log_path% ( echo"Backup Pull Log">%log_path% )
rem 拉取最新代码 cd %git_file_path% if %errorlevel% neq 0 goto fail
git reset --hard if %errorlevel% neq 0 goto fail
git fetch --all if %errorlevel% neq 0 goto fail
git pull origin %git_branck% if %errorlevel% neq 0 goto fail
rem 移动到备份 :movefile move %git_file_path%\test\* %storage_file_path% if %errorlevel% neq 0 goto fail goto success