search
HomeDatabaseMysql Tutorialmssql定时备份数据库方法

mssql定时备份数据库方法

Jun 07, 2016 pm 05:47 PM
mssqlbackuptimingdatabasemethod

mssql定时备份数据库方法//方法一要用远程数据库可以备份本地。 本地数据库也可以备份到远程。

mssql定时备份方法
//方法一

要用远程数据库可以备份本地。
本地数据库也可以备份到远程。

--备份环境:把数据库服务器(192.168.1.8)的数据库(TEST)备份到(192.168.1.145)的C$下

--首先,做一个与客户端的映射
exec master..xp_cmdshell
'net use z: "密码" /user:192.168.1.145administrator'


--其次,进行数据库备份
backup database TEST to disk='z:Test.bak'

--最后.备份完成后删除映射
exec master..xp_cmdshell 'net use z: /delete'
--来自网络


--以下代码放在作业里做调度,自动备份、自动删除4天前备份

--创建映射
exec master..xp_cmdshell 'net use w: DatabaseBackup$  "password"/user:Roy',NO_OUTPUT
go
-----2000用游标:www.111cn.net
declare @s nvarchar(200),@del nvarchar(200)
select  @s='',@del=''

declare datebak cursor for
select
    [bak]='backup database  '+quotename(Name)+'  to disk =''w:'+Name+'_'+convert(varchar(8),getdate(),112)+'.bak''  with init',
    [del]='exec master..xp_cmdshell '' del w:'+Name+'_'+convert(varchar(8),getdate()-4,112)+'.bak'', no_output'
from master..sysdatabases where dbid>4 --不备份系统数据库
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
--删除映射
exec master..xp_cmdshell 'net use w: /delete'

go

--用JOB.
--SQL SERVER2000为例

企业管理器—>数据库服务器—>管理目

录—>SQL SERVER代理—>作业—>右键 选—>新建

常规选项页—>输入作业名称—>选中所有者。

步骤选项页—>新建—>输入步骤名—>类型 TSQL脚本—>选择需要执行的数据库—>在命令框里输入你的SQL 脚本:

如:update tb set 状态= ...  where 日期...........

你可以点左下角的【分析】按钮,分析一下语法,分析无误,按确定。

调度选项页—>新建调度—>输入调度名称—>调度类型 你可以选择也可以点右下角的【更改】按钮进行更改,确定。

任务栏 SQL SERVER服务器的小图标 双击 服务 选中 SQL SERVER AGENT,点【开始/继续】,选中当启动OS时,自动启动服务,就可以了。

到你定的那个时间点,SQL SERVER会自动去执行你的脚本的。

如果需要生成脚本的话,企业管理器—>数据库服务器—>管理目录—>SQL SERVER代理—>作业—>右键你刚完成的作业—>所有任务

—>生成SQL脚本,即可生成你需要的脚本。
//方法二

企业管理器——管理——数据库维护计划
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What Are the Limitations of Using Views in MySQL?What Are the Limitations of Using Views in MySQL?May 14, 2025 am 12:10 AM

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

Securing Your MySQL Database: Adding Users and Granting PrivilegesSecuring Your MySQL Database: Adding Users and Granting PrivilegesMay 14, 2025 am 12:09 AM

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

What Factors Influence the Number of Triggers I Can Use in MySQL?What Factors Influence the Number of Triggers I Can Use in MySQL?May 14, 2025 am 12:08 AM

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

MySQL: Is it safe to store BLOB?MySQL: Is it safe to store BLOB?May 14, 2025 am 12:07 AM

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

MySQL: Adding a user through a PHP web interfaceMySQL: Adding a user through a PHP web interfaceMay 14, 2025 am 12:04 AM

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use