Home Database Mysql Tutorial 自动备份mssql server数据库并压缩的批处理脚本

自动备份mssql server数据库并压缩的批处理脚本

Jun 07, 2016 pm 06:02 PM
mssql Automatic backup

windows下,使用mssql命令行工具sqlcmd备份数据库,并调用rar压缩;不借助mssql维护计划功能,拜托权限问题。

1. set bakupfolder=F:\backup\
备份文件存放于目录F:\backup\ (此目录需要事先建好)
2. 默认每个数据库放置到bakupfolder下的同名的子目录(脚本自动创建)中;设置lay_in_subfolder=0后,将直接放置到bakupfolder
3. 备份文件名中自动添加备份时的时间字符串,不用担心备份目录下名字重复,也便于管理。
4. call :backupone foo
foo是需要备份的数据库,需要备份其它数据库,按同样的方式一行写一条即可
5. 命令行驱动备份操作:sqlcmd -U sa -P “sa” -S localhost -Q “xxx”
这里连接数据库的用户名密码都是sa,请改成你的实际用户名密码。mssql密码中如果有一些特殊字符,可能报错,所以加上双引号。如果密码简单,不加也可以;不过sa密码,一般都是很变态的吧~~

代码如下:
@ECHO ON
set d=%date:~0,10%
set d=%d:-=%
set t=%time:~0,8%
set t=%t::=%
set stamp=%p%%d%%t%
set bakupfolder=F:\backup\
rem 1按子目录保存备份文件;0不按
set lay_in_subfolder=1
call :backupone foo
call :backupone foo2
call :backupone foo3
call :backupone foo4
goto :EOF
@ECHO OFF
:backupone
setlocal
echo %1
set dbname=%1
if not exist %bakupfolder%%dbname% mkdir %bakupfolder%%dbname%
if %lay_in_subfolder%==1 (
set subfolder=%dbname%\
)else set subfolder=
rem echo %bakupfolder%%subfolder%%dbname%%stamp%.bak
sqlcmd -U sa -P "sa" -S localhost -Q "backup database %dbname% to disk='%bakupfolder%%subfolder%%dbname%%stamp%.bak'"
"C:\Program Files\WinRAR\RAR.exe" a -ep1 -r -o+ -m5 -s -df "%bakupfolder%%subfolder%%dbname%%stamp%".rar "%bakupfolder%%subfolder%%dbname%%stamp%.bak"
endlocal&goto :EOF
Statement of this Website
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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to disable automatic backup in Windows 10 How to disable automatic backup in Windows 10 Apr 18, 2024 pm 07:49 PM

Some Windows 10 users have found that the system's built-in automatic backup function is activated during use. Although this function helps ensure data security, some users may not feel the need to continue enabling it due to storage space considerations or other reasons. This function. Therefore, if you want to turn off the automatic backup function in Windows 10 system, the correct operation steps are particularly important. Next, this article will introduce in detail how to turn off the automatic backup function of the Win10 system for the reference implementation of users who have this need. Close method 1. Use the "win+i" shortcut key to quickly open the "Settings" page. After entering the new page, you need to click the "Update and Security" option. 2. In the new interface that opens, click in the left column

How to connect php to mssql database How to connect php to mssql database Oct 23, 2023 pm 12:02 PM

Methods for php to connect to mssql database include using PHP's MSSQL extension, using PDO, etc. Detailed introduction: 1. Use PHP's MSSQL extension method to ensure that PHP has the MSSQL extension installed. You can check whether the mssql extension is enabled in the PHP configuration file (php.ini); 2. Use the PDO method to ensure that PHP has the PDO extension installed. You can check whether the pdo_sqlsrv extension is enabled in the PHP configuration file (php.ini).

How to implement automatic backup of MySQL database with PHP How to implement automatic backup of MySQL database with PHP May 16, 2023 am 08:54 AM

With the popularity of Internet applications, database backup is particularly important for website operation and maintenance and data security. Manual backup can certainly provide certain protection, but for websites with large amounts of data, manual backup is obviously cumbersome and time-consuming. At this time, the automatic backup method has become an indispensable choice. One of the more popular and easy-to-understand automatic backup methods is to use PHP scripts to automatically backup the MySQL database. This article will introduce how to use PHP to implement automatic backup of MySQL database. 1. Backup My

How to automatically back up Quark Network Disk - How to automatically back up Quark Network Disk How to automatically back up Quark Network Disk - How to automatically back up Quark Network Disk Mar 04, 2024 pm 11:00 PM

Are you also using Quark Network Disk software? But do you know how to automatically back up Quark Network Disk? The editor below will bring you the method of automatic backup of Quark Network Disk, let us take a look below. Open Quark Network Disk on the desktop. Click on my avatar to enter the main interface. Click the Quark Network Disk automatic backup option to turn it on.

Detailed guide to install PHP and configure MSSQL connection on Ubuntu Detailed guide to install PHP and configure MSSQL connection on Ubuntu Feb 29, 2024 am 11:15 AM

Ubuntu is a popular open source operating system commonly used to run servers. Installing PHP and configuring MSSQL connections on Ubuntu is one of the operations that many developers and system administrators often need to do. This article will provide readers with a detailed guide, including the steps to install PHP, set up Apache, install MSSQLServer, etc., and attach specific code examples. Step 1: Install PHP and related extensions First, we need to install PHP and related extensions to support PHP connections

Detailed steps to install PHP to support MSSQL database in Ubuntu environment Detailed steps to install PHP to support MSSQL database in Ubuntu environment Feb 29, 2024 am 10:39 AM

Detailed steps for installing PHP to support MSSQL database in Ubuntu environment. When developing web applications, you often encounter situations where you need to connect to the Microsoft SQL Server (MSSQL) database. In the Ubuntu environment, to connect PHP to the MSSQL database, you need to install relevant software and configure appropriate settings. Next, we will introduce in detail the steps to install PHP to support MSSQL database in Ubuntu environment and provide specific code.

Where to enable automatic backup of router settings on Xiaomi wifi_How to enable automatic backup of router settings on Xiaomi wifi Where to enable automatic backup of router settings on Xiaomi wifi_How to enable automatic backup of router settings on Xiaomi wifi Mar 25, 2024 pm 06:11 PM

1. Enter Xiaomi WiFi and click on the toolbox in the lower right corner. 2. Find the routing settings. 3. Enter the router configuration backup. 4. Click to turn on automatic backup of router settings.

How to automatically back up specified folders in Windows 7 How to automatically back up specified folders in Windows 7 Mar 26, 2024 pm 06:01 PM

1. Press the [Win+R] keys to open the run; as shown in the figure: 2. Enter cmd in the following window to open the command line window; as shown in the figure: 3. Enter the command robocopy in the command line window to view it. Corresponding parameter description; as shown in the figure: 4. For example, to automatically back up the demo folder under E drive to the demo folder under H drive every 10 minutes, use the following command: robocopyE:demoD:demo/R:0/ W:0/MOT:10; As shown in the figure: 5. The parameter R above represents the number of retries after the backup fails, W is the retry interval, and MOT represents the time interval of automatic backup; as shown in the figure: 6 . After the automatic backup is completed, you can see the automatically backed up folder under the D drive.

See all articles