PDA

View Full Version : بکاب گیری زمانبندی شده



zare69
پنج شنبه 20 مهر 1391, 11:05 صبح
دوستان سلام
من می خوام ی Jobایجاد کنم که به صورت زمانبندی شده (روزانه سرساعت) از بانک بکاب بگیرید من کدهای زیر از اینترنت پیدا کردم ولی هرکاریش می کنم درست اجرا نمی شود.اصلا نمیدونم داخل فایل MetrixBackup.bat چی قرار بگیرد.
لطفا منو راهنمایی کنید

------------------------------------WARNING------------------------------------
---------------------DO NOT EDIT - Variable Declarations-----------------------
-------------------------------------------------------------------------------
DECLARE @DatabaseName nvarchar(128), @ServerName nvarchar(300), @BackupFilePathAndName nvarchar(300), @BackupTime nvarchar(50), @BATFilePathAndName nvarchar(300)

------------------------------------WARNING------------------------------------
-------------------DO NOT EDIT - Prerequisites Description---------------------
-------------------------------------------------------------------------------
/*In order for this script to work you must
1) supply values for the variables declared above
2) run this script on the same server where the database resides
3) ensure that SQL Server Agent is running on the server*/


------------------------------------WARNING------------------------------------
-------------------EDIT - Supply values below for the variables----------------
--------------------NOTE: When editing the variables---------------------------
------DO NOT overwrite the single quotes (') or else the script will fail------
------For example, change 'YourDatabaseNameHere' to 'MyMetrixDatabase'---------
-------------------------------------------------------------------------------
--@DatabaseName - The name of the database to be backed up
SET @DatabaseName = 'YourDatabaseNameHere'
--@ServerName - Name of the server where the database resides. Include the instance, e.g. MyServer\METRIX if necessary.
SET @ServerName = 'YourServerNameHere'
--@BackupFilePathAndName - The file path and name of the backup file
SET @BackupFilePathAndName = 'C:\Program Files\fcny\Metrix\DailyBackups\YourBackupFileNameH ere.dat'
--@BackupTime - The time when the backup should be executed (24 hr military time). Should be no more than six numbers.
--For example, 143000 is 2:30 pm and no seconds
SET @BackupTime = '000000'
--@BATFilePathAndName - The location of the .BAT file that will rename the backup file to include the date and time
--NOTE 1: ONLY CHANGE THE FILE PATH!! The file name must remain the same
--For example if you change the path from "C" to "D", @BATFilePathAndName should be 'D:\RenameBackup.bat'
--NOTE 2: If you change the path you must also change it in the RenameBackup.bat.
--To edit RenameBackup.bat, right-click on the file name and select 'Edit', NOT 'Open'
SET @BATFilePathAndName = 'C:\MetrixBackup.bat'

------------------------------------WARNING------------------------------------
----------DO NOT EDIT - Code that creates and schedules the backup-------------
-------------------------------------------------------------------------------

-- Create the SQL Server job.
EXECUTE('USE msdb
EXEC sp_add_job @job_name = ''MetrixBackupJob'',
@enabled = 1,
@description = ''MetrixBackupJob'',
@owner_login_name = ''sa'',
@notify_level_eventlog = 2,
@notify_level_email = 2,
@notify_level_netsend =2,
@notify_level_page = 2')

-- Add job step (backup data file, .mdf).
EXECUTE('USE msdb
EXEC sp_add_jobstep @job_name = ''MetrixBackupJob'',
@step_name = ''Backup Metrix Data'',
@subsystem = ''TSQL'',
@command = ''BACKUP DATABASE ' + @DatabaseName + ' TO DISK = ''''' + @BackupFilePathAndName + ''''''',
@on_success_action = 3,
@retry_attempts = 5,
@retry_interval = 5')

-- Add job step to rename the backup file
EXECUTE('USE msdb
EXEC sp_add_jobstep @job_name = ''MetrixBackupJob'',
@step_name = ''Rename backup file'',
@subsystem = ''CmdExec'',
@command = N''' + @BATFilePathAndName + ''',
@on_success_action = 1,
@retry_attempts = 5,
@retry_interval = 5')

-- Add the target servers.
EXECUTE('USE msdb
EXEC sp_add_jobserver @job_name = ''MetrixBackupJob'', @Server_name = N''' + @ServerName + '''')

-- Schedule the job.
EXECUTE('USE msdb
EXEC sp_add_jobschedule @job_name = ''MetrixBackupJob'',
@name = ''Backup Metrix Data'',
@freq_type = 4,
@freq_interval = 1,
@active_start_time = ''' + @BackupTime + '''')