How to back up data to a different machine in SQL Server

Source: Internet
Author: User

Two methods are provided here:

1. Write the stored procedure and create a scheduled job backup.

-- Ing in SQL
Exec master.. xp_mongoshell 'net use Z: \ computer_name \ D $ "password"/User: computer_name \ Administrator'
/* -- Description:
Z: indicates the drive letter of the local machine corresponding to the ing network path, which corresponds to the following Backup
\ Computer_name \ D $ is the network path to be mapped
Computer_name is the name of a remote computer,
Administrator is the Login User Name
Password of the specified administrator user
--*/
-- Backup; with init overwrite ¦ noinit to add
Backup database name to disk = 'e: \ h_backup.bak 'with init
-- Copy
Exec master .. xp_mongoshell 'Copy E: \ h_backup.bak Z :'
-- Delete (this sentence can be removed)
-- Exec master .. xp_mongoshell 'del E: \ h_backup.bak'
-- Delete the ing after the ing is completed
Exec master.. xp_mongoshell 'net use Z:/delete'

2. Scheduling

Enterprise Manager -- manage -- SQL Server proxy -- Right-click a job -- create a job -- enter the job name in "general" -- "Step" -- create -- "Step name" and enter the step name in "Step name -- select "Transact-SQL script (tsql)" from "type) "--" Database "select the database for command execution --" command "and enter the statement to be executed:
Declare @ strsql varchar (1000)
Declare @ strdirname varchar (50)
Declare @ strcmd varchar (50)
Declare @ strsend varchar (1000)
Declare @ strdate varchar (50)
Exec master.. xp_mongoshell 'net use \ 192.168.0.151 \ D $ password/User: 192.168.0.151 \ Administrator'
Set @ strsql = 'backup database new_his to disk = ''\ 192.168.0.151 \ D $ \ serverd \'
Set @ strdirname = Replace (substring (convert (varchar (20), getdate (), 120),), '-', '') + '12'
Set @ strcmd = 'md \ 192.168.0.151 \ D $ \ serverd \'s
Et @ strcmd = @ strcmd + @ strdirname
Exec master .. xp_mongoshell @ strcmd
-- Print @ strsql
Set @ strsql = @ strsql + @ strdirname + '\ new_hisbackup.dat' with init, nounload, noskip, noformat '-
-Print @ strsql
Exec (@ strsql)
---- The IP addresses and shared directories written here are modified by the netizens themselves, password must be correct -- OK -- "scheduling" item -- create scheduling -- enter the scheduling name in "name" -- select your job execution schedule in "scheduling type" -- if "appears repeatedly ""-- click" change "to set your schedule and start the SQL Agent service, and set it to automatic start. Otherwise, your job will not be executed as follows: my computer -- control panel -- Administrative Tools -- service -- Right-click SQLServerAgent -- properties -- start type -- select "auto start" -- OK.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.