SQL Server Remote Backup Database

Source: Internet
Author: User

SQL Server Remote Backup Database

Regular backup of SQL Server databases is often required. It is quite easy to back up data to the local machine on a regular basis and the task can be completed. However, if the entire machine crashes, it makes no sense to back up data to the local machine, therefore, we need to consider backing up data to the LAN and other computers.

Next, I will share a piece of code that I just sorted out on the Internet. With the job function in the SQL Server proxy, it has been running stably for a week and backed up every hour.

-- Create a network ing (Y is the drive letter; the IP address must be followed by the name of the shared folder; password is the password, caused by double quotation marks; account is the login name of the remote computer)
Exec master.. xp_mongoshell 'net use Y: \ 192.168.0.69 \ sqlbackup "password"/user: 192.168.0.69 \ account'
-- Create a file name by date and time (note that the folder in the path must be created first)
Declare @ filename varchar (200)
Select @ filename = 'y: \ DB \ '+ replace (CONVERT (varchar, getdate (), 120 ),'-',''),'', '-'), ':', ') + '. bak'
-- Backup (DB is the name of the database to be backed up)
Backup database [DB] to disk = @ filename
-- Delete the network ing (Y is the drive letter, same as above)
Exec master.. xp_mongoshell 'net use Y:/delete'

This article permanently updates the link address:

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.