数据库自动备份
DECLARE @BAKPATH NVARCHAR(200)
DECLARE @DATABASENAME NVARCHAR(200)
set @BAKPATH = convert(NVARCHAR(19),getdate(),23)
set @BAKPATH = 'D:\database_bak\' + 'HXcms_'+@BAKPATH + '.bak'
BACKUP DATABASE [HXcms] TO DISK = @BAKPATH WITH NOINIT , NOUNLOAD , NOSKIP , STATS = 10, NOFORMAT
数据库自动删除
DECLARE @OLDDATE DATETIME
SELECT @OLDDATE=GETDATE()-9
EXECUTE master.dbo.xp_delete_file 0,N'D:\database_bak',N'bak',@olddate,0
本地保存文件(创建.bat系统文件)
::删除并保留最近的两个rar备份文件,然后创建新的备份文件
@echo off
rem 文件夹名称
set foldername="User"
rem 保存的压缩文件夹目标路径,包含文件名
set despath="D:\guziimages_bak\User.rar"
rem 保存的压缩文件夹目标路径
set desfolderpath="D:\guziimages_bak"
rem 要压缩的文件夹路径
set orgpath="D:\guziimages\User"
rem 要压缩的文件所在盘符
d:
echo 将 %orgpath% 压缩到 %desfolderpath% 文件自动添加时间和后缀 如:User_YYYYMMDDHHMMSS_1.rar
cd %desfolderpath%
set count=0
for %%i in (%foldername%_*.rar) do (
set /a count+=1
)
if %count% == 3 (
del %foldername%_*_1.rar
ren %foldername%_*_2.rar %foldername%_*_1.rar
ren %foldername%_*_3.rar %foldername%_*_2.rar
rar a -r -ep1 -ag_YYYYMMDDHHMMSS_3 %despath% %orgpath%
)
if %count% == 2 (
rar a -r -ep1 -ag_YYYYMMDDHHMMSS_3 %despath% %orgpath%
)
if %count% == 1 (
rar a -r -ep1 -ag_YYYYMMDDHHMMSS_2 %despath% %orgpath%
)
if %count% == 0 (
rar a -r -ep1 -ag_YYYYMMDDHHMMSS_1 %despath% %orgpath%
)
ping -n 3 127.1 >nul
exit