- 前言
visual source safe 里有代码,sql server 里有数据,这就是项目的全部。
拥有他们就拥有了全部,所以这些东西的安全实在是重要。
本文以批处理的方式,实现了全自动备份vss和全部sql数据库的功能。
- 备份数据库:
并将备份的日志写入backup_database_log.txt,为避免重名覆盖将文件名修改为backup_database_log_%DATE%.txt,
形如:backup_database_log_2011-10-09.txt。
@echo off @echo start to backup database osql -E -i auto_backup_db.sql -o backup_database_log.txt @echo finished backup database FOR /F "tokens=1-3 delims=- " %%i IN ('date /t') DO SET DATE=%%i-%%j-%%k rename "backup_database_log.txt" "backup_database_log_%DATE%.txt" @echo on
USE master go DECLARE @bak_path NVARCHAR(200) DECLARE @bak_file_name NVARCHAR(200) --设置文件备份路径 SET @bak_path = 'E:\DataBaseBAK' --利用游标遍历,逐个备份数据库 DECLARE @db_name SYSNAME DECLARE cur_database CURSOR FOR SELECT [name]-- 查询所有数据库 FROM sys.databases WHERE [state] = 0 -- 0 = ONLINE 在线状态 AND [name] NOT IN ( 'master', 'model', 'msdb', 'tempdb', 'ReportServer','ReportServerTempDB') --系统数据库、演示数据库除外 OPEN cur_database FETCH NEXT FROM cur_database INTO @db_name WHILE ( @@FETCH_STATUS = 0 ) BEGIN --设置备份文件名称,形如:dbname_2011-10-09.bak SET @bak_file_name = @bak_path + '\' + @db_name + '_' + CONVERT(VARCHAR(10), GETDATE(), 120) + '.bak' --开始完整备份 BACKUP DATABASE @db_name TO DISK = @bak_file_name FETCH NEXT FROM cur_database INTO @db_name END CLOSE cur_database DEALLOCATE cur_database
- 自动备份vss auto_backup_vss.bat
@ECHO OFF @TITLE Backing up source safe databases SET VSS_Install_Path="C:\Program Files\Microsoft Visual SourceSafe\" SET VSS_DB="\\192.168.0.244\vss" SET Bak_File="e:\%DATE%_vss_backup.ssa" SET VSS_Admin_Name="admin" SET VSS_Admin_Password="your_password" FOR /F "tokens=1-3 delims=- " %%i IN ('date /t') DO SET DATE=%%i-%%j-%%k %VSS_Install_Path%"ssarc" -d- -y%VSS_Admin_Name%,%VSS_Admin_Password% -s%VSS_DB% %Bak_File% $/ @ECHO finished backup vss
请根据情况修改这些条目:
VSS_Install_Path = vss的安装路径
VSS_DB = vss数据库路径
Bak_File = 备份文件路径
VSS_Admin_Password=vss超级管理员密码