SQL Server Remote timed backup database script sharing, SQL Server
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.
Copy codeThe Code is as follows:
-- 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'