zoukankan      html  css  js  c++  java
  • 怎么用SQL语句备份和恢复数据库?

    BACKUP DATABASE "mydb" TO DISK ='C:mybak.db' with init

    RESTORE DATABASE "mydb" FROM DISK='C:mybak.db';

    --完整备份
    Backup Database NorthwindCS
    To disk='G:BackupNorthwindCS_Full_20070908.bak'

    --差异备份
    Backup Database NorthwindCS
    To disk='G:BackupNorthwindCS_Diff_20070908.bak'
    With Differential

    --日志备份,默认截断日志
    Backup Log NorthwindCS
    To disk='G:BackupNorthwindCS_Log_20070908.bak'

    --日志备份,不截断日志
    Backup Log NorthwindCS
    To disk='G:BackupNorthwindCS_Log_20070908.bak'
    With No_Truncate

    --截断日志不保留
    Backup Log NorthwindCS
    With No_Log

    --或者
    Backup Log NorthwindCS
    With Truncate_Only
    --截断之后日志文件不会变小
    --有必要可以进行收缩

    --文件备份
    Exec Sp_Helpdb NorthwindCS --查看数据文件
    Backup Database NorthwindCS
    File='NorthwindCS' --数据文件的逻辑名
    To disk='G:BackupNorthwindCS_File_20070908.bak'

    --文件组备份
    Exec Sp_Helpdb NorthwindCS --查看数据文件
    Backup Database NorthwindCS
    FileGroup='Primary' --数据文件的逻辑名
    To disk='G:BackupNorthwindCS_FileGroup_20070908.bak'
    With init

    --分割备份到多个目标
    --恢复的时候不允许丢失任何一个目标
    Backup Database NorthwindCS
    To disk='G:BackupNorthwindCS_Full_1.bak'
    ,disk='G:BackupNorthwindCS_Full_2.bak'

    --镜像备份
    --每个目标都是相同的
    Backup Database NorthwindCS
    To disk='G:BackupNorthwindCS_Mirror_1.bak'
    Mirror
    To disk='G:BackupNorthwindCS_Mirror_2.bak'
    With Format --第一次做镜像备份的时候格式化目标

    --镜像备份到本地和远程
    Backup Database NorthwindCS
    To disk='G:BackupNorthwindCS_Mirror_1.bak'
    Mirror
    To disk='\192.168.1.200BackupNorthwindCS_Mirror_2.bak'
    With Format

    --每天生成一个备份文件
    Declare @Path Nvarchar(2000)
    Set @Path ='G:BackupNorthwindCS
  • 相关阅读:
    IO模型
    协程
    线程
    进程总结
    HashMap和Hashtable有什么区别
    HashMap 1.7 与 1.8 的 区别,说明 1.8 做了哪些优化,如何优化的
    GC线程是否为守护线程?
    float f=3.4;是否正确?
    final、finally和finalized的区别?
    Eureka注册中心是什么?
  • 原文地址:https://www.cnblogs.com/dianyitongxiao/p/3229416.html
Copyright © 2011-2022 走看看