One, create a backup script
GO
DECLARE
@backuptime varchar(20)
DECLARE
@filename varchar(100)
select @backuptime=convert(varchar(8),getdate(),112)
select @filename='D:\Database_backup\DB_'+@backuptime+'.bak'
backup database [DB] to disk=@filename
select @filename='D:\Database_backup\DG_'+@backuptime+'.bak'
backup database [DG] to disk=@filename
select @filename='D:\Database_backup\DGoal_'+@backuptime+'.bak'
backup database [DGoal] to disk=@filename
Save as D:\Database_backup\backup_sql.sql
Two, create an executable file
sqlcmd -S .\SQL2008R2 -U sa -P sa2008r2 -i D:\Database_backup\backup_sql.sql
Save as D:\Database_backup\ backup_sql.bat
Description of file content:
.\SQL2008R2 service name; sa user name; sa2008r2 password; D:\Database_backup\backup_sql.sql execution script path
Three, create windows timing tasks
Control Panel-Management Tools-Task Scheduler (Create basic tasks)
Fourth, clean up the backup files 60 days ago
::Delete the backup file (suffix bak) 60 days ago
F:
cd F:/dbbak
forfiles /S /M *.bak -d -60 /c "cmd /c del /f @path"
Save as D:\Database_backup\ del_bak.bat