Backup to diffrent server and domain

  • Hi all,

    I am trying to address a backup strategy; were I must backup a database and restore to a different server on a different domain. I have tried using the SQL 2005 copy wizard with out success. I am attempting to backup an SQL 2000 database and restoring to a SQL 2005

    I will need to be able to do the following:

    1. pass the user information of the destination server from the source server

    2. execute backup command from the source domain/server

    I am open to any suggestions available using

    osql

    sqlcmd

    vbs script

    batch file

    any and all help will be greatly appreciated.

  • Hi all,

    I have worked on a solution to solve my issue for backing up and restoring to a different domain and server. The statement below is the job scripted out. Please feel free to add you comments as I was stuck trying to make this work with copy wizard and this is what I came up with . This worked for me and solve my issue.

    USE [msdb]

    GO

    /****** Object: Job [Backup from production] Script Date: 10/15/2007 09:53:55 ******/

    BEGIN TRANSACTION

    DECLARE @ReturnCode INT

    SELECT @ReturnCode = 0

    /****** Object: JobCategory [Database Maintenance] Script Date: 10/15/2007 09:53:55 ******/

    IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'Database Maintenance' AND category_class=1)

    BEGIN

    EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'Database Maintenance'

    IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

    END

    DECLARE @jobId BINARY(16)

    select @jobId = job_id from msdb.dbo.sysjobs where (name = N'Backup from production')

    if (@jobId is NULL)

    BEGIN

    EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'Backup from production',

    @enabled=1,

    @notify_level_eventlog=0,

    @notify_level_email=3,

    @notify_level_netsend=2,

    @notify_level_page=2,

    @delete_level=0,

    @description=N'No description available.',

    @category_name=N'Database Maintenance',

    @owner_login_name=N'UserName',

    @notify_email_operator_name=N' ',

    @notify_netsend_operator_name=N' ',

    @notify_page_operator_name=N' ', @job_id = @jobId OUTPUT

    IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

    END

    /****** Object: Step [Delete Old Backup] Script Date: 10/15/2007 09:53:55 ******/

    IF NOT EXISTS (SELECT * FROM msdb.dbo.sysjobsteps WHERE job_id = N'34041459-8cbc-4a38-ba74-ce98c740e488' and step_id = 1)

    EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Delete Old Backup',

    @step_id=1,

    @cmdexec_success_code=0,

    @on_success_action=3,

    @on_success_step_id=0,

    @on_fail_action=2,

    @on_fail_step_id=0,

    @retry_attempts=0,

    @retry_interval=0,

    @os_run_priority=0, @subsystem=N'TSQL',

    @command=N'master.sys.xp_cmdshell ''del E:\DBBACKUPS\ .BAK''',

    @database_name=N'master',

    @flags=0

    IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

    /****** Object: Step [Backup ] Script Date: 10/15/2007 09:53:56 ******/

    IF NOT EXISTS (SELECT * FROM msdb.dbo.sysjobsteps WHERE job_id = N'34041459-8cbc-4a38-ba74-ce98c740e488' and step_id = 2)

    EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Backup ',

    @step_id=2,

    @cmdexec_success_code=0,

    @on_success_action=3,

    @on_success_step_id=0,

    @on_fail_action=2,

    @on_fail_step_id=0,

    @retry_attempts=0,

    @retry_interval=0,

    @os_run_priority=0, @subsystem=N'CmdExec',

    @command=N'sqlcmd -S .sql',

    @flags=0

    IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

    /****** Object: Step [Restore ] Script Date: 10/15/2007 09:53:56 ******/

    IF NOT EXISTS (SELECT * FROM msdb.dbo.sysjobsteps WHERE job_id = N'34041459-8cbc-4a38-ba74-ce98c740e488' and step_id = 3)

    EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Restore ',

    @step_id=3,

    @cmdexec_success_code=0,

    @on_success_action=3,

    @on_success_step_id=0,

    @on_fail_action=2,

    @on_fail_step_id=0,

    @retry_attempts=0,

    @retry_interval=0,

    @os_run_priority=0, @subsystem=N'TSQL',

    @command=N'use master

    Restore Database

    FROM DISK = ''E:\dbbackups\ .BAK''

    With Recovery, Replace,

    MOVE '' .mdf'',

    MOVE '' .ldf''

    go

    use

    EXEC sp_change_users_login ''Auto_Fix'', '' ''

    go

    use master

    EXEC sp_change_users_login ''Auto_Fix'', '' ''',

    @database_name=N'master',

    @flags=0

    IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

    /****** Object: Step [Set Database compatible level to SQL Server 2005 and Change Recovery Mode] Script Date: 10/15/2007 09:53:56 ******/

    IF NOT EXISTS (SELECT * FROM msdb.dbo.sysjobsteps WHERE job_id = N'34041459-8cbc-4a38-ba74-ce98c740e488' and step_id = 4)

    EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Set Database compatible level to SQL Server 2005 and Change Recovery Mode',

    @step_id=4,

    @cmdexec_success_code=0,

    @on_success_action=1,

    @on_success_step_id=0,

    @on_fail_action=2,

    @on_fail_step_id=0,

    @retry_attempts=0,

    @retry_interval=0,

    @os_run_priority=0, @subsystem=N'TSQL',

    @command=N'EXEC sp_dbcmptlevel , 90;

    go

    ALTER Database

    SET RECOVERY SIMPLE;

    GO

    -- Grant execute to all store procedures and functions

    GRANT EXECUTE TO ',

    @database_name=N'master',

    @flags=0

    IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

    EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1

    IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

    EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'Backup and Restore to WEGRSSPSD03',

    @enabled=1,

    @freq_type=4,

    @freq_interval=1,

    @freq_subday_type=1,

    @freq_subday_interval=0,

    @freq_relative_interval=0,

    @freq_recurrence_factor=0,

    @active_start_date=20071014,

    @active_end_date=99991231,

    @active_start_time=40000,

    @active_end_time=235959

    IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

    EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'

    IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

    COMMIT TRANSACTION

    GOTO EndSave

    QuitWithRollback:

    IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION

    EndSave:

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply