Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Hi, everyone. I need help about SQL 2000 server.

Hi, everyone. I need help about SQL 2000 server.

Scheduled Pinned Locked Moved Database
databasesysadminagentic-aihelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jlizardo
    wrote on last edited by
    #1

    Hi, everyone. I need help to SQL 2000 server in relation to obtain a backup for any database. I have some trouble using the backup of SQL 2000 server because the SQL agent must be stop first before start the backup. How I can automaticly start a backup without user interaction with the server? Johnny Lizardo

    R 1 Reply Last reply
    0
    • J jlizardo

      Hi, everyone. I need help to SQL 2000 server in relation to obtain a backup for any database. I have some trouble using the backup of SQL 2000 server because the SQL agent must be stop first before start the backup. How I can automaticly start a backup without user interaction with the server? Johnny Lizardo

      R Offline
      R Offline
      Rob Graham
      wrote on last edited by
      #2

      What you want to do is add a scheduled task for SQLServerAgent, and let it do the backup on a scheduled basis. If you have enterprise manager, use the database amintenace wizared to create the backup jobs. If not the TSQL code below will create a weekkly backup schedule, rotating the backup file name and overwiting the oldest. (there is a better way to do this, sql can manage the retention for you, but this is all I had handy)

      BEGIN
      BEGIN TRANSACTION
      DECLARE @JobID BINARY(16)
      DECLARE @ReturnCode INT
      SELECT @ReturnCode = 0
      IF (SELECT COUNT(*) FROM msdb.dbo.syscategories WHERE name = N'[Uncategorized (Local)]') < 1
      EXECUTE msdb.dbo.sp_add_category @name = N'[Uncategorized (Local)]'

      -- Delete the job with the same name (if it exists)
      SELECT @JobID = job_id FROM msdb.dbo.sysjobs WHERE (name = N'MyDatabase backup1')
      IF (@JobID IS NOT NULL) BEGIN
      -- Check if the job is a multi-server job
      IF (EXISTS (SELECT *
      FROM msdb.dbo.sysjobservers
      WHERE (job_id = @JobID) AND (server_id <> 0)))
      BEGIN
      -- There is, so abort the script
      RAISERROR (N'Unable to import job ''MyDatabase backup1'' since there is already a multi-server job with this name.', 16, 1)
      GOTO QuitWithRollback
      END
      ELSE
      -- Delete the [local] job
      EXECUTE msdb.dbo.sp_delete_job @job_name = N'MyDatabase backup1'
      SELECT @JobID = NULL
      END

      BEGIN

      -- Add the job
      EXECUTE @ReturnCode = msdb.dbo.sp\_add\_job @job\_id = @JobID OUTPUT , @job\_name = N'MyDatabase backup1', @owner\_login\_name = N'sa', @description = N'No description available.', @category\_name = N'\[Uncategorized (Local)\]', @enabled = 1, @notify\_level\_email = 0, @notify\_level\_page = 0, @notify\_level\_netsend = 0, @notify\_level\_eventlog = 2, @delete\_level= 0
      IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
      
      -- Add the job steps
      EXECUTE @ReturnCode = msdb.dbo.sp\_add\_jobstep @job\_id = @JobID, @step\_id = 1, @step\_name = N'Step 1', @command = N'sp\_Hmx\_BackupDb ''MyDatabase'',''D:\\Database\\DbBackups'',''MyDatabase1.BAK''', @database\_name = N'MyDatabase', @server = N'', @database\_user\_name = N'', @subsystem = N'TSQL', @cmdexec\_success\_code = 0, @flags = 0, @retry\_attempts = 0, @retry\_interval = 0, @output\_file\_name = N'', @on\_success\_step\_id = 0, @on\_success\_action = 1, @on\_fail\_step\_id = 0, @on\_fail\_action = 2
      IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
      EXECUTE @ReturnCode = msdb.dbo.sp\_update\_job @job\_id = @JobID, @start\_step\_id = 1
      
      IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWith
      
      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups