bat批处理WinRAR备份文件夹或文件

服务器技术 4 年前 回复

, , , ,

REM @echo off
REM ::使用之后就会显示新的标题框了
REM title 自动备份程序
REM : Backup to bakFolder must be change youself
REM ::[Edit][所要备份到的指定目录]
REM set baktagFolder="D:\backup"
REM : U want backups Folder must be change Youself
REM ::[Edit][需要备份的文件]
REM set sorFolder="D:\zz"
REM :set time to vir
REM set stry=%date:~0,4%&& set strm=%date:~5,2%&& set strd=%date:~8,2%
REM set strh=%time:~0,2%&& set strmin=%time:~3,2%
REM set strdatt=%stry%%strm%%strd%
REM set strlongdatt=%strdatt%%strh%%strmin%
REM ::[Edit][改变文件名字命名规则]
REM : Backup to bakFolder by Date (year month day)& Time (hour min)
REM if not exist %baktagFolder% mkdir %baktagFolder%
REM if not exist %baktagFolder%\%strdatt% mkdir %baktagFolder%\%strdatt%
REM :: cd /d %sorFolder%
REM xcopy %sorFolder%\* /s/y %baktagFolder%\%strdatt%

REM @echo 数据备份完成,3秒后程序退出。

REM ping /n 3 127.0.0.1 >nul

REM exit

@echo off
color 0b & cls
echo 本批处理小程序为元林哥哥所创
echo ==============================================================
echo    =======   =                     ===          =    =
echo       =     =                    =======      ====  ====
echo       =                            = =         ===  ===
echo       =        ==     ==           = =        = = =  = =
echo       =       =  =   =  =         =  =       =  =    =  =
echo       =      =    ==     =       =   =   =  =   =    =   =
echo    =======  =             =    =      ====      =    =
echo ==============================================================
title 欢迎进入元林哥哥压缩备份小程序 
echo 正在查找要备份的文件夹...  
set "pbuf=D:\家家购物软件"  
echo 正在安排备份文件存放文件夹...
set "tbuf=E:\backup"  
if not exist %tbuf% mkdir %tbuf%

echo 初始化压缩程序设置...  
cd \  
C:  
cd C:\Program Files\WinRAR  
set yes=ok  
echo 压缩程序在C:\Program Files\WinRAR\WinRAR.exe  
  
echo 设置备份文件名(以星期几命名,即备份文件只保存最近一周)...  
set name=%date%  
set name=%name:~-3%  
set name=backup_%name%  
 
echo 检查是否存在同名文件,若存在则删除同名文件...  
if exist %tbuf%\%name%.rar del %tbuf%\%name%.rar

set startime=%time:~0,2%%time:~3,2%%time:~6,2%
echo 备份开始时间是%time:~0,2%点%time:~3,2%分%time:~6,2%秒 > %tbuf%\%name%.txt

echo 开始执行压缩备份...  
rar a -k -r -ed -esh %tbuf%\%name%.rar %pbuf%\*.*  >> %tbuf%\%name%.txt

set endtime=%time:~0,2%%time:~3,2%%time:~6,2%
echo 备份结束时间是%time:~0,2%点%time:~3,2%分%time:~6,2%秒 >> %tbuf%\%name%.txt

set /a finaltime=%endtime%-%startime%
echo 备份耗时%finaltime%秒 >> %tbuf%\%name%.txt

echo 备份完毕,3秒后程序退出!
ping /n 3 127.0.0.1 >nul
exit

注释部分为文件直接copy备份,下面是用WinRAR压缩文件压缩备份文件。

支付宝打赏微信打赏

如果此文对你有帮助,欢迎打赏作者。

发表评论

欢迎回来 (打开)

(必填)