SQL Server remote timed Backup database script sharing _mssql

Source: Internet
Author: User

Regular backups of the SQL Server database are often required. Regular backup to this machine, or quite easy, planning tasks can be completed, but if the machine is hung, that backup to this machine is meaningless, then you need to consider backup to the local area network, other computers.

The following is a share of a search on the internet after the simple collation of their own code, with the SQL Server agent in the job function, has been stable operation for one weeks, every hour on the backup.

Copy Code code as follows:

--Create a network map (y is the letter; the name of the shared folder after the IP address; password is the password, double quotes; account is the remote computer's login name)

EXEC master.. xp_cmdshell ' net use Y: \\192.168.0.69\sqlbackup ' password '/user:192.168.0.69\account '

--By date Time file name (note the folder in the path, you need to first set up)

DECLARE @filename varchar (200)

Select @filename = ' Y:\DB\ ' + replace (replace (CONVERT (varchar, GETDATE (), (), '-', '), ', '-'), ': ', ') + '. Bak '

--Perform a backup (db is the name of the database to be backed up)

Backup DATABASE [DB] to disk = @filename

--delete Network map (y is the letter, IBID.)

EXEC master.. xp_cmdshell ' net use Y:/delete '

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.