- ---备份
USE MASTER
GO
EXEC sp_configure ‘show advanced options‘, 1;
RECONFIGURE WITH OVERRIDE;
EXEC sp_configure ‘xp_cmdshell‘, 1;
RECONFIGURE WITH OVERRIDE;
GO
EXEC MASTER ..xp_cmdshell ‘net use \\sharef.cn\Share\DataBackup\SQLBackupData01 "password" /user:sharef\username‘
GO
---\\sharef.cn\Share\DataBackup\SQLBackupData01 为中间存储备份文件的 存储服务器共享路径CREATE LOGIN [backup_link_user] WITH PASSWORD=N‘[email protected]‘, DEFAULT_DATABASE=[master], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO
USE [DBA_Maintenance]
GO
CREATE USER [backup_link_user] FOR LOGIN [backup_link_user]
GO
USE [DBA_Maintenance]
GO
ALTER ROLE [db_datareader] ADD MEMBER [backup_link_user]
GO
USE [DBA_Maintenance]
GO
ALTER ROLE [db_datawriter] ADD MEMBER [backup_link_user]
GO
USE [msdb]
GO
CREATE USER [backup_link_user] FOR LOGIN [backup_link_user]
GO
USE [msdb]
GO
ALTER ROLE [db_datareader] ADD MEMBER [backup_link_user]GO
USE DBA_Maintenance
GO
CREATE PROCEDURE PRO_Archive_BackupData
AS
BEGIN
SET NOCOUNT ON
DECLARE @NOW DATETIME=GETDATE()
DECLARE @condition DATETIME
SET @condition=dateadd(day,-3,@NOW)DELETE db_backup_record
OUTPUT DELETED.*,@NOW
INTO db_backup_archive
WHERE backup_end<[email protected] and is_restore=1SET NOCOUNT OFF
END
GO
CREATE PROCEDURE [dbo].[PRO_BACKUP_DB]
(
@Instance nvarchar(128)=NULL,
@DB_NAME SYSNAME,
@TYPE VARCHAR(12), --FULL DIFF LOG
@BACK_PATH VARCHAR(512)
)
WITH ENCRYPTION
AS
--version1.1
BEGIN
SET NOCOUNT ONDECLARE @BACKUP_FULL_SQL NVARCHAR(1280)
DECLARE @BACKUP_DIFF_SQL NVARCHAR(1280)
DECLARE @BACKUP_LOG_SQL NVARCHAR(1280)
DECLARE @DATE_SERIAL_NUMBER NVARCHAR(16)IF @Instance IS NULL
BEGIN
SET @[email protected]@SERVICENAME
END
SET @DATE_SERIAL_NUMBER=‘_‘+‘‘+CONVERT(varchar(8), GETDATE(), 112)+ replace(convert(char(5), getdate(), 108), ‘:‘, ‘‘)+‘‘
IF @DB_NAME IS NULL
BEGIN
PRINT ‘Database Does not Exist‘
RETURN 1;
END
IF NOT EXISTS(SELECT NAME FROM MASTER.SYS.DATABASES WHERE [email protected]_NAME)
BEGIN
PRINT ‘[‘ + @DB_NAME + ‘] is not a valid database name!‘
RETURN 1;
ENDIF @TYPE NOT IN (‘FULL‘,‘DIFF‘,‘LOG‘)
BEGIN
PRINT ‘Database backup type must be [full], [log] or [diff]!‘
RETURN 1;
ENDDECLARE @EXISTS_INSTANCE_SQL NVARCHAR(512)
DECLARE @EXISTS_INSTANCE_FOLDER TABLE(COL NVARCHAR(512))
DECLARE @EXISTS_FOLDER TABLE(COL NVARCHAR(512))
DECLARE @EXISTS_SQL NVARCHAR(512)
DECLARE @EXISTS_SHAREFLODER_SQL NVARCHAR(512)
DECLARE @MKDIR_SQL NVARCHAR(512)
DECLARE @MKDIR_INSTANCE_SQL NVARCHAR(512)SET @EXISTS_SHAREFLODER_SQL=N‘EXEC MASTER..XP_CMDSHELL ‘‘DIR‘+CHAR(9)+‘‘[email protected]_PATH+‘‘‘‘
SET @EXISTS_INSTANCE_SQL=N‘EXEC MASTER..XP_CMDSHELL ‘‘DIR‘+CHAR(9)+‘‘[email protected]_PATH+‘\‘[email protected]+‘‘‘‘
SET @EXISTS_SQL=N‘EXEC MASTER..XP_CMDSHELL ‘‘DIR‘+CHAR(9)+‘‘[email protected]_PATH+‘\‘[email protected]+‘\‘[email protected]_NAME+‘‘‘‘
SET @MKDIR_INSTANCE_SQL=N‘EXEC MASTER..XP_CMDSHELL ‘‘MKDIR‘+CHAR(9)+‘‘[email protected]_PATH+‘\‘[email protected]+‘‘‘, NO_OUTPUT‘
SET @MKDIR_SQL=N‘EXEC MASTER..XP_CMDSHELL ‘‘MKDIR‘+CHAR(9)+‘‘[email protected]_PATH+‘\‘[email protected]+‘\‘[email protected]_NAME+‘‘‘, NO_OUTPUT‘INSERT INTO @EXISTS_FOLDER EXEC SP_EXECUTESQL @EXISTS_SHAREFLODER_SQL,N‘@BACK_PATH NVARCHAR(128)‘,@BACK_PATH
IF EXISTS (SELECT 1 FROM @EXISTS_FOLDER WHERE COL LIKE ‘%File Not Found%‘)
BEGIN
PRINT ‘[‘[email protected]_PATH+‘] is not a valid !‘
RETURN 2;
END
INSERT INTO @EXISTS_INSTANCE_FOLDER EXEC SP_EXECUTESQL @EXISTS_INSTANCE_SQL,N‘@BACK_PATH NVARCHAR(128),@Instance NVARCHAR(128)‘,@BACK_PATH,@Instance
IF EXISTS (SELECT 1 FROM @EXISTS_INSTANCE_FOLDER WHERE COL LIKE ‘%File Not Found%‘)
BEGIN
EXEC SP_EXECUTESQL @MKDIR_INSTANCE_SQL,N‘@BACK_PATH NVARCHAR(128),@Instance NVARCHAR(128)‘,@BACK_PATH,@Instance
END
INSERT INTO @EXISTS_FOLDER EXEC SP_EXECUTESQL @EXISTS_SQL,N‘@BACK_PATH NVARCHAR(128),@Instance NVARCHAR(128),@DB_NAME NVARCHAR(128)‘,@BACK_PATH,@Instance,@DB_NAME
IF EXISTS(SELECT 1 FROM @EXISTS_FOLDER WHERE COL LIKE ‘%File Not Found%‘)
BEGIN
EXEC SP_EXECUTESQL @MKDIR_SQL,N‘@BACK_PATH NVARCHAR(128),@Instance NVARCHAR(128),@DB_NAME NVARCHAR(128)‘,@BACK_PATH,@Instance,@DB_NAME
END
IF RIGHT(@BACK_PATH,1)=‘\‘
BEGIN
SET @BACK_PATH=LEFT(@BACK_PATH,LEN(@BACK_PATH)-1)
ENDDECLARE @ERROR INT
DECLARE @BACKUP_FILENAME VARCHAR(512)
DECLARE @BACKUP_BEGIN DATETIME
IF @TYPE=‘FULL‘
BEGIN
SET @BACKUP_FULL_SQL=N‘BACKUP DATABASE‘+CHAR(9)+‘[‘[email protected]_NAME+‘]‘+CHAR(9)
+‘TO DISK= ‘‘‘[email protected]_PATH+‘\‘[email protected]+‘\‘[email protected]_NAME+‘\‘[email protected][email protected]_SERIAL_NUMBER+‘.BAK‘‘‘+CHAR(9)+‘WITH NOFORMAT, NOINIT,‘
+‘NAME=N‘‘‘[email protected]_NAME+‘-FULL Database Backup‘‘, SKIP, NOREWIND, NOUNLOAD, STATS = 10‘
SET @[email protected][email protected]_SERIAL_NUMBER+‘.BAK‘
--EXEC (@BACKUP_FULL_SQL)
SET @BACKUP_BEGIN=GETDATE()
EXEC SP_EXECUTESQL @BACKUP_FULL_SQL,N‘@DB_NAME NVARCHAR(128),@BACK_PATH NVARCHAR(128),@Instance NVARCHAR(128),@DATE_SERIAL_NUMBER NVARCHAR(16)‘,@DB_NAME,@BACK_PATH,@Instance,@DATE_SERIAL_NUMBER
SET @[email protected]@ERROR
END
IF @TYPE=‘DIFF‘
BEGIN
SET @BACKUP_DIFF_SQL=N‘BACKUP DATABASE‘+CHAR(9)+‘[‘[email protected]_NAME+‘]‘+CHAR(9)
+‘TO DISK= ‘‘‘[email protected]_PATH+‘\‘[email protected]+‘\‘[email protected]_NAME+‘\‘[email protected][email protected]_SERIAL_NUMBER+‘.DIFF‘‘‘+CHAR(9)+‘WITH DIFFERENTIAL , NOFORMAT, NOINIT,‘
+‘NAME=N‘‘‘[email protected]_NAME+‘-Differential Database Backup‘‘, SKIP, NOREWIND, NOUNLOAD, STATS = 10‘
SET @[email protected][email protected]_SERIAL_NUMBER+‘.DIFF‘
--EXEC (@BACKUP_DIFF_SQL)
SET @BACKUP_BEGIN=GETDATE()
EXEC SP_EXECUTESQL @BACKUP_DIFF_SQL,N‘@DB_NAME NVARCHAR(128),@BACK_PATH NVARCHAR(128),@Instance NVARCHAR(128),@DATE_SERIAL_NUMBER NVARCHAR(16)‘,@DB_NAME,@BACK_PATH,@Instance,@DATE_SERIAL_NUMBER
SET @[email protected]@ERROR
END
IF @TYPE=‘LOG‘
BEGIN
SET @BACKUP_LOG_SQL=N‘BACKUP LOG‘+CHAR(9)+‘[‘[email protected]_NAME+‘]‘+CHAR(9)
+‘TO DISK= ‘‘‘[email protected]_PATH+‘\‘[email protected]+‘\‘[email protected]_NAME+‘\‘[email protected][email protected]_SERIAL_NUMBER+‘.TRN‘‘‘+CHAR(9)+‘WITH NOFORMAT, NOINIT,‘
+‘NAME=N‘‘‘[email protected]_NAME+‘-Transaction Log Backup‘‘, SKIP, NOREWIND, NOUNLOAD, STATS = 10‘
SET @[email protected][email protected]_SERIAL_NUMBER+‘.TRN‘
--EXEC (@BACKUP_LOG_SQL)
SET @BACKUP_BEGIN=GETDATE()
EXEC SP_EXECUTESQL @BACKUP_LOG_SQL,N‘@DB_NAME NVARCHAR(128),@BACK_PATH NVARCHAR(128),@Instance NVARCHAR(128),@DATE_SERIAL_NUMBER NVARCHAR(16)‘,@DB_NAME,@BACK_PATH,@Instance,@DATE_SERIAL_NUMBER
SET @[email protected]@ERROR
END
IF @ERROR=0
BEGIN
--INSERT INTO DBA_Maintenance.dbo.db_backup_record select @DB_NAME,@BACKUP_BEGIN,getdate(), @BACK_PATH+‘\‘[email protected]+‘\‘[email protected]_NAME,@TYPE,@BACKUP_FILENAME,0 --version 1.0
INSERT INTO DBA_Maintenance.dbo.db_backup_record select @DB_NAME,@BACKUP_BEGIN,getdate(), @BACK_PATH+‘\‘[email protected]+‘\‘[email protected]_NAME+‘\‘[email protected]_FILENAME,@TYPE,0 --version 1.1
ENDSET NOCOUNT OFF
END---还原
USE MASTER
GO
EXEC sp_configure ‘show advanced options‘, 1;
RECONFIGURE WITH OVERRIDE;
EXEC sp_configure ‘xp_cmdshell‘, 1;
RECONFIGURE WITH OVERRIDE;
GO
EXEC MASTER ..xp_cmdshell ‘net use \\sharef.cn\Share\DataBackup\SQLBackupData01 "password" /user:sharef\username‘
GOGO
CREATE LOGIN [backup_link_user] WITH PASSWORD=N‘[email protected]‘, DEFAULT_DATABASE=[master], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO
USE [DBA_Maintenance]
GO
CREATE USER [backup_link_user] FOR LOGIN [backup_link_user]
GO
USE [DBA_Maintenance]
GO
ALTER ROLE [db_datareader] ADD MEMBER [backup_link_user]
GO
USE [DBA_Maintenance]
GO
ALTER ROLE [db_datawriter] ADD MEMBER [backup_link_user]
GO
USE [msdb]
GO
CREATE USER [backup_link_user] FOR LOGIN [backup_link_user]
GO
USE [msdb]
GO
ALTER ROLE [db_datareader] ADD MEMBER [backup_link_user]
GOEXEC sp_addlinkedserver
@server=‘VCST004003IS01‘ ,--被访问的服务器别名
@srvproduct=‘‘ ,
@provider=‘SQLOLEDB‘ ,
@datasrc=‘vcst004003sl01.sharef.cn\vcst004003is01‘ --要访问的服务器
EXEC sp_addlinkedsrvlogin
‘VCST004003IS01‘, --被访问的服务器别名
‘false‘,
NULL,
‘backup_link_user‘, --帐号
‘[email protected]‘ --密码
GOCREATE PROCEDURE [dbo].[PRO_AccordingTo_Parameters_Restore_DB]
(
@Instance nvarchar(128)=NULL,--暂时无用
@DB_NAME NVARCHAR(128)=NULL,
@TYPE NVARCHAR(16), --FULL DIFF LOG
@RESTORE_PATH NVARCHAR(128)=N‘\\sharef.cn\Share\DataBackup\SQLBackupData01\SQLBackupData01\VCST004005IS01‘,
@LOCAL_DBFILES_PATH NVARCHAR(512)=N‘T:\MSSQL11.VWSR027002IS02\MSSQL\DATA\‘,
@DATE_TIME DATETIME=NULL
)
WITH ENCRYPTION
AS
BEGIN
SET NOCOUNT ONDECLARE @RESTORE_PATH_FILENAME NVARCHAR(512)
DECLARE @RESTORE_FULL_SQL NVARCHAR(4000)
DECLARE @RESTORE_DIFF_SQL NVARCHAR(4000)
DECLARE @RESTORE_LOG_SQL NVARCHAR(4000)
DECLARE @ERROR INT=0
DECLARE @i int=1
DECLARE @count int=1DECLARE @RESTORE_BEGIN DATETIME
DECLARE @EXISTS_FOLDER TABLE(COL NVARCHAR(512))
DECLARE @EXISTS_RESTOREDB_FOLDER_SQL NVARCHAR(512)IF @DATE_TIME IS NULL AND @TYPE=‘FULL‘
BEGIN
SET @DATE_TIME=DATEADD(day,-3,getdate())
END
IF @DATE_TIME IS NULL AND @TYPE=‘DIFF‘
BEGIN
SET @DATE_TIME=DATEADD(hour,-3,getdate())
END
IF @TYPE NOT IN (‘FULL‘,‘DIFF‘,‘LOG‘)
BEGIN
PRINT ‘Please Specify The Type Of The Restore Database ([full], [log] or [diff])!‘
RETURN;
END
IF @RESTORE_PATH IS NULL
BEGIN
PRINT ‘The Path To Restore Database Cannot Be Empty!‘
RETURN;
END
ELSE
BEGIN
SET @EXISTS_RESTOREDB_FOLDER_SQL=N‘EXEC MASTER..XP_CMDSHELL ‘‘DIR‘+CHAR(9)+‘‘[email protected]_PATH+‘\‘[email protected]_NAME+‘‘‘‘
INSERT INTO @EXISTS_FOLDER EXEC SP_EXECUTESQL @EXISTS_RESTOREDB_FOLDER_SQL,N‘@RESTORE_PATH NVARCHAR(128),@DB_NAME NVARCHAR(128)‘,@RESTORE_PATH,@DB_NAME
IF EXISTS (SELECT 1 FROM @EXISTS_FOLDER WHERE COL LIKE ‘%File Not Found%‘)
BEGIN
PRINT ‘[‘[email protected]_PATH+‘] is not a valid !‘
RETURN;
END
END
IF RIGHT(@RESTORE_PATH,1)=‘\‘
BEGIN
SET @RESTORE_PATH=LEFT(@RESTORE_PATH,LEN(@RESTORE_PATH)-1)
END
DECLARE @tmp TABLE (rn int,dbname sysname,backup_type varchar(16),backup_path_filename nvarchar(512))
DECLARE @RESTORE_TYPE VARCHAR(6)
IF @TYPE=‘FULL‘
BEGIN
SET @RESTORE_TYPE=‘D‘
END
IF @TYPE=‘DIFF‘
BEGIN
SET @RESTORE_TYPE=‘I‘
END
IF @TYPE=‘LOG‘
BEGIN
SET @RESTORE_TYPE=‘L‘
END
INSERT INTO @tmp SELECT ROW_NUMBER() over(order by database_name)rn,BACKUP_DATA.database_name, BACKUP_DATA.backup_type,BACKUP_DATA.physical_device_name
FROM
(
SELECT
bjs.database_name,
CASE bjs.type
WHEN ‘D‘ THEN ‘Database‘
WHEN ‘L‘ THEN ‘Log‘
WHEN ‘I‘ THEN ‘DIFF‘
END AS backup_type,
bkmf.physical_device_name,
bjs.first_lsn,bjs.last_lsn,
bjs.database_backup_lsn,
bjs.backup_finish_dateFROM [VCST004005sl01].[msdb].[dbo].[backupmediafamily] AS bkmf WITH(NOLOCK)
INNER JOIN [VCST004005sl01].[msdb].[dbo].[backupset] AS bjs WITH(NOLOCK)
ON bkmf. media_set_id=bjs.media_set_id
WHERE bjs.RECOVERY_MODEL=‘FULL‘
AND [email protected]_TYPE
AND bjs.backup_finish_date>[email protected]_TIME
AND bjs.database_name not in (‘master‘,‘msdb‘,‘model‘,‘tempdb‘,‘DBA_Maintenance‘)
)AS BACKUP_DATA
WHERE NOT EXISTS( SELECT 1
FROM msdb .dbo. backupset AS bus WITH(NOLOCK)
WHERE BACKUP_DATA.database_name=bus.database_name
AND BACKUP_DATA.first_lsn= bus.first_lsn
AND BACKUP_DATA.last_lsn=bus.last_lsn
AND bus.backup_finish_date>[email protected]_TIME
AND [email protected]_TYPE
)
AND NOT EXISTS (SELECT 1 FROM (SELECT database_name,MAX(backup_finish_date)backup_finish_date
FROM msdb .dbo. backupset AS bus WITH(NOLOCK)
WHERE bus.backup_finish_date>[email protected]_TIME
AND [email protected]_TYPE
GROUP BY database_name
)tmp
WHERE BACKUP_DATA.database_name=tmp.database_name
AND BACKUP_DATA.backup_finish_date<=tmp.backup_finish_date
)SELECT @count=count(*) from @tmp
WHILE @i<[email protected]
BEGINSET @DB_NAME=NULL
SET @RESTORE_PATH_FILENAME=NULL
SET @RESTORE_PATH=NULL
SET @ERROR=0SELECT @DB_NAME=dbname,
@RESTORE_PATH_FILENAME=backup_path_filename
FROM @tmp WHERE [email protected]DECLARE @FileListInfo TABLE
(
LogicalName nvarchar(512) null,
PhysicalName nvarchar(512) null,
Type varchar(16) null,
FileGroupName nvarchar(128) null,
FileSize bigint null ,
FileMaxSize Bigint null,
FileId bigint,
CreateLSN numeric(25,0),
DropLSN numeric(25,0) NULL,
UniqueID uniqueidentifier,
ReadOnlyLSN numeric(25,0) NULL,
ReadWriteLSN numeric(25,0) NULL,
BackupSizeInBytes bigint,
SourceBlockSize int,
FileGroupID int,
LogGroupGUID uniqueidentifier NULL,
DifferentialBaseLSN numeric(25,0) NULL,
DifferentialBaseGUID uniqueidentifier,
IsReadOnly bit,
IsPresent bit,
TDEThumbprint nvarchar(128)
)DECLARE @Get_FilelistSQL nvarchar(max)
SET @Get_FilelistSQL = N‘RESTORE FILELISTONLY FROM DISK = N‘‘‘[email protected]_PATH_FILENAME+‘‘‘‘+CHAR(9)
INSERT INTO @FileListInfo EXEC SP_EXECUTESQL @Get_FilelistSQLDECLARE @LogicalName_D NVARCHAR(512)
DECLARE @LogicalName_L NVARCHAR(512)
SELECT @LogicalName_D=LogicalName FROM @FileListInfo WHERE Type=‘D‘
SELECT @LogicalName_L=LogicalName FROM @FileListInfo WHERE Type=‘L‘
IF @TYPE=‘FULL‘
BEGIN
SET @RESTORE_FULL_SQL=N‘RESTORE DATABASE‘+CHAR(9)+‘[‘[email protected]_NAME+‘]‘+CHAR(9)
+‘FROM DISK= ‘‘‘[email protected]_PATH_FILENAME+‘‘‘‘+CHAR(9)
+‘WITH FILE = 1,MOVE N‘‘‘[email protected]_NAME+‘‘‘ TO N‘‘‘[email protected][email protected]_D+‘.MDF‘‘,
MOVE N‘‘‘[email protected]_NAME+‘_LOG ‘‘ TO N‘‘‘[email protected][email protected]_L+‘.LDF‘‘,NORECOVERY, NOUNLOAD, REPLACE, STATS = 5‘
SET @RESTORE_BEGIN =GETDATE()
EXEC SP_EXECUTESQL @RESTORE_FULL_SQL
,N‘@DB_NAME NVARCHAR(128),@RESTORE_PATH_FILENAME NVARCHAR(512),@LOCAL_DBFILES_PATH NVARCHAR(512),@LogicalName_D NVARCHAR(128),@LogicalName_L NVARCHAR(128)‘
,@DB_NAME,@RESTORE_PATH_FILENAME,@LOCAL_DBFILES_PATH,@LogicalName_D,@LogicalName_L
SET @[email protected][email protected]@ERROR
END
IF @TYPE=‘DIFF‘
BEGIN
SET @RESTORE_DIFF_SQL=N‘RESTORE DATABASE‘+CHAR(9)+‘[‘[email protected]_NAME+‘]‘+CHAR(9)
+‘FROM DISK= ‘‘‘[email protected]_PATH_FILENAME+‘‘‘‘+CHAR(9)
+‘WITH FILE = 1,MOVE N‘‘‘[email protected]_NAME+‘‘‘ TO N‘‘‘[email protected][email protected]_D+‘.MDF‘‘,
MOVE N‘‘‘[email protected]_NAME+‘_LOG ‘‘ TO N‘‘‘[email protected][email protected]_L+‘.LDF‘‘,NORECOVERY, NOUNLOAD, REPLACE, STATS = 10‘
SET @RESTORE_BEGIN =GETDATE()
EXEC SP_EXECUTESQL @RESTORE_DIFF_SQL
,N‘@DB_NAME NVARCHAR(128),@RESTORE_PATH_FILENAME NVARCHAR(512),@LOCAL_DBFILES_PATH NVARCHAR(512),@LogicalName_D NVARCHAR(128),@LogicalName_L NVARCHAR(128)‘
,@DB_NAME,@RESTORE_PATH_FILENAME,@LOCAL_DBFILES_PATH,@LogicalName_D,@LogicalName_L
SET @[email protected][email protected]@ERROR
END
IF @TYPE=‘LOG‘
BEGIN
SET @RESTORE_LOG_SQL=N‘RESTORE LOG‘+CHAR(9)+‘[‘[email protected]_NAME+‘]‘+CHAR(9)
+‘FROM DISK= ‘‘‘[email protected]_PATH_FILENAME+‘‘‘‘+CHAR(9)
+‘WITH FILE = 1,NORECOVERY, NOUNLOAD, STATS = 10‘
SET @RESTORE_BEGIN =GETDATE()
EXEC SP_EXECUTESQL @RESTORE_LOG_SQL
,N‘@DB_NAME NVARCHAR(128),@RESTORE_PATH_FILENAME NVARCHAR(512)‘
,@DB_NAME,@RESTORE_PATH_FILENAME
SET @[email protected][email protected]@ERROR
END
IF @ERROR=0
BEGIN
INSERT INTO DBA_Maintenance.dbo.db_restory_record (dbname,restore_begin,restore_end,restore_type,restore_filename,flag)
VALUES (@DB_NAME,@RESTORE_BEGIN,GETDATE(),@TYPE,@RESTORE_PATH_FILENAME,1)
END
SET @[email protected]+1
ENDSET NOCOUNT OFF
ENDGO
数据库异地备份还原
时间: 2024-10-11 20:15:38
数据库异地备份还原的相关文章
吐槽阿里云数据库的备份还原
阿里云数据库RDS备份还原问题终于解决了.我会告诉你其实不用看他们的文档,直接还原就可以了吗? 详情如下: 我严格按照文档操作的,后来数据库启动过几秒后即崩溃,有两个错误,先解决了一个,后来一个用了各种办法都解决不了. 于是只好留言阿里云的客服,我着重强调了严格按照文档,并提交了崩溃信息. 结果客服说,请按文档操作,好吧. 后来看了一下阿里云提供的工具,一个导出脚本居然1M多,我的天,什么脚本这么大.于是看了一下代码,就是个简单的解压操作, 后面塞了一堆二进制,让人以为很高端,其实普通的解压软件
mongodb 数据库操作--备份 还原 导出 导入
一,mongodump备份数据库 1,常用命令格 1 mongodump -h IP --port 端口 -u 用户名 -p 密码 -d 数据库 -o 文件存在路径 如果没有用户谁,可以去掉-u和-p. 如果导出本机的数据库,可以去掉-h. 如果是默认端口,可以去掉--port. 如果想导出所有数据库,可以去掉-d. 2,导出所有数据库 1 2 3 4 5 6 7 8 9 10 [[email protected] mongodb]# mongodump -h 127.0.0.1 -o /hom
数据库的备份还原
数据库的复制与附加 (一)分离: 1.把SqlServer服务停了,把.mdf和.ldf,ndf复制出来.然后再启动服务. 2.在SQLServer的操作界面中,右击要复制的数据库--所有任务--分离.把.mdf和.ldf,ndf复制出来. (二)附加 在SQLServer对象资源管理器中,在"数据库"上右击--选择"附加"--在弹出的窗口选择要附加.mdf文件,点击确定. 注意:两个文件.mdf和.ldf要有访问权限.Everyone完全控制. 数据库的备
C#中MySQL数据库的备份 还原 初始化
// 执行创建数据库操作 this.GetExecute(G_Con, "create database if not exists NEWDB"); this.sqlAddress = " -h " + IP + " -u" + User + " -p" + Password + " NEWDB "; // 数据库的备份 private void btn_Dump_Click(object sender,
DB2数据库在线备份还原笔记
数据库在线增量备份 由于一般客户的生产系统数据量都很大,所以频繁的进行数据库或表空间的全量备份在空间存储上变得不可行.DB2 支持两种增量的备份,一种是增量备份(comulative backup),另一种是差异备份(deltabackup).总的说来,增量的备份(包括增量备份和差异备份),在其备份映像文件中只包含自上次进行备份以来有过更新的页,除更新的数据和索引页之外,每个增量备份映像还包含通常存储在完全备份映像中的初始数据库元数据(例如,数据库配置.表空间定义和数据库历史记录等).增量
C# MySQL数据库的备份 还原 初始化
// 执行创建数据库操作 this.GetExecute(G_Con, "create database if not exists NEWDB"); this.sqlAddress = " -h " + IP + " -u" + User + " -p" + Password + " NEWDB "; // 数据库的备份 private void btn_Dump_Click(object sender,
mongodb数据库操作--备份 还原 导出 导入
首先数据库备份: mongodump -h IP --port 端口 -u 用户名 -p 密码 -d 数据库 -o 文件存在路径 mongodump -h 127.0.0.1 -u admin -p xxx -d blog -o '/home/timeless/桌面/mongodump' --authenticationDatabase admin 注意 --authenticationDatabase 参数制定认证数据库 否则会提示错误: Failed: error connecti
数据库异地备份(脚本)
一:前期准备 至少需要两台主机 192.168.175.200 vip 192.168.175.250 node1 做密钥否则不能拷贝过去 命令:[[email protected] ~]#cd /root/.ssh 命令:[[email protected] .ssh]#ssh-copy-id -i id_rsa.pub 192.168.175.250 测试一下,命令:[[email protected] .ssh]# ssh 192.168.175.250
SQL Server 第四堂课 用数据库语言while 循环做累加求和。以及数据库的备份,还原,分离,附加。以及check 约束
drop proc qiuhe create proc qiuhe --用数据库语言做累加求和 @n int as declare @sum int --相当于C#语言里定义变量 declare @i int set @sum=0 --再给变量赋值 ,相当于C#语言里的 int sum=0 set @i=1 -- 相当于for 循环里的 int i=1 (int i=1;i<=n;i++) while @i<[email protected] --for(int i=1;i<=n;i++