• 批量执行sql脚本文件


    RestoreAndUpgrade - termsdev.gratte.com.bat:

    @Echo off
    set server=46.32.226.206
    set database=WASPPSDEV
    set user=
    set password=
    set backupfilepath=C:\FtpRoot\TERMS\Backup\UatServer\Databases\waspps\WASPPSv53.bak

    Echo Are you sure you want to overwrite the database %database% on server %server%?
    Pause

    REM Disconnect All Users
    Echo Switching %database% to single user mode to disconnect all other users
    sqlcmd /U%user% /P%password% /S%server% /Q "ALTER DATABASE %database% SET SINGLE_USER WITH ROLLBACK IMMEDIATE"

    REM Restore the backup
    Echo Restoring backup from %backupfilepath%
    sqlcmd /U%user% /P%password% /S%server% /Q "RESTORE DATABASE %database% FROM DISK = N'%backupfilepath%' WITH FILE = 1, NOUNLOAD, REPLACE, STATS = 10"

    REM Allow all users back in
    Echo Switching %database% to multi user mode to allow user to connect
    sqlcmd /U%user% /P%password% /S%server% /Q "ALTER DATABASE %database% SET MULTI_USER WITH ROLLBACK IMMEDIATE"

    @Echo Run All Scripts Now?
    pause
    REM Run All Scripts
    for %%f in (*.sql) do sqlcmd /U%user% /P%password% /S%server% /d%database% /i "%%f"

    cd..
    cd Final_Static_Data
    for %%f in (*.sql) do sqlcmd /U%user% /P%password% /S%server% /d%database% /i "%%f"

    @Echo All Done
    pause

    RestoreAndUpgradeLocalServer-Waspps.bat:

    @Echo off
    set server=.
    set database=WASPPS
    set user=
    set password=
    set backupfilepath=%~dp0WASPPSv53.bak

    Echo Are you sure you want to overwrite the database %database% on server %server%?
    Pause

    REM Disconnect All Users
    Echo Switching %database% to single user mode to disconnect all other users
    sqlcmd /S%server% /Q "ALTER DATABASE %database% SET SINGLE_USER WITH ROLLBACK IMMEDIATE"

    REM Restore the backup
    Echo Restoring backup from %backupfilepath%
    sqlcmd /S%server% /Q "RESTORE DATABASE %database% FROM DISK = N'%backupfilepath%' WITH FILE = 1, NOUNLOAD, REPLACE, STATS = 10"

    REM Allow all users back in
    Echo Switching %database% to multi user mode to allow user to connect
    sqlcmd /S%server% /Q "ALTER DATABASE %database% SET MULTI_USER WITH ROLLBACK IMMEDIATE"

    @Echo Run All Scripts Now?
    pause
    REM Run All Scripts
    @Echo On
    for %%f in (*.sql) do sqlcmd /S%server% /d%database% /i "%%f"

    cd..
    cd Final_Static_Data
    for %%f in (*.sql) do sqlcmd /S%server% /d%database% /i "%%f"

    @Echo Off
    @Echo All Done
    pause

  • 相关阅读:
    17 电话号码的字母组合(LeetCode HOT 100)
    11 盛最多水的容器(LeetCode HOT 100)
    20 有效的括号(LeetCode HOT 100)
    22 括号生成(LeetCode HOT 100)
    31 下一个排列(LeetCode HOT 100)
    20191324网络对抗EXP2后门原理与实践
    20191324《网络对抗》Exp3免杀原理与实践
    20191324hash碰撞实例
    Golang 可以运行 但是 github 包标红
    Redishash基本使用
  • 原文地址:https://www.cnblogs.com/cw_volcano/p/2995909.html
Copyright © 2020-2023  润新知