Mssql database backup method

Source: Internet
Author: User
Method 1: Use a remote database to back up a local database. Local databases can also be backed up remotely.

Mssql regular backup database method // method 1 use a remote database to back up local data. Local databases can also be backed up remotely.

Mssql scheduled backup method
// Method 1

Use a remote database to back up local data.
Local databases can also be backed up remotely.

-- Backup environment: Back up the database server (192.168.1.8) database (TEST) to C $(192.168.1.145 ).

-- First, perform a ing with the client
Exec master .. xp_mongoshell
'Net use z: "password"/user: 192.168.1.145administrator'


-Second, back up the database
Backup database TEST to disk = 'z: Test. Bak'

-- Finally, delete the ing after the backup is complete.
Exec master.. xp_mongoshell 'net use z:/delete'
-- From Network


-- Run the following code in the job for scheduling: automatic backup and automatic deletion of backups four days ago

-- Create a ing
Exec master.. xp_mongoshell 'net use w: DatabaseBackup $ "password"/user: Roy ', NO_OUTPUT
Go
----- 2000 use a cursor: www.111cn.net
Declare @ s nvarchar (200), @ del nvarchar (200)
Select @ s = '', @ del =''

Declare datebak cursor
Select
[Bak] = 'backup database' + quotename (Name) + 'to disk = ''w:' + Name + '_' + convert (varchar (8 ), getdate (), 112) + '. bak ''with init ',
[Del] = 'exec master .. xp_mongoshell ''del w: '+ Name +' _ '+ convert (varchar (8), getdate ()-4,112) + '. bak '', no_output'
From master.. sysdatabases where dbid> 4 -- do not back up the system database
Open datebak

Fetch next from datebak into @ s, @ del
While @ fetch_status = 0
Begin
Exec (@ del)
Exec (@ s)
Fetch next from datebak into @ s, @ del
End
Close datebak
Deallocate datebak
Go
-- Delete ing
Exec master.. xp_mongoshell 'net use w:/delete'

Go

-- Use JOB.
-- SQL SERVER2000

Enterprise Manager-> database server-> management object

Choose> SQL SERVER proxy> job> right-click and choose> New

General options page-> enter a job name-> select the owner.

On the step Options page, choose new> enter the step Name> TSQL script type> select the database to be executed> enter your SQL script in the Command box:

For example, update tb set status =... where date ...........

Click the "analysis" button in the lower left corner to analyze the syntax, analyze the syntax correctly, and press "OK.

On the scheduling option page, choose create scheduling and enter the scheduling name. You can select a scheduling type or click Change in the lower right corner to change the scheduling type.

Double-click the icon of the SQL server in the taskbar to select the SQL server agent and click Start/continue. When the OS is started, the service is automatically started.

At the specified time point, SQL SERVER will automatically execute your script.

If you need to generate a script, choose Enterprise Manager> Database SERVER> Manage directory> SQL SERVER proxy> job> right-click the job you just completed> all tasks

-> Generate an SQL script to generate the script you need.
// Method 2

Enterprise Manager-management-database maintenance plan

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.