服务器常用批处理代码 原创
程序员文章站
2022-03-22 08:42:38
将下面的内容保存为sqlreboot.bat,然后添加到计划任务里,就可以实现一段时间后重启sqlserver服务器了,防止sqlserver经常占用内存过高,导致网页无法...
将下面的内容保存为sqlreboot.bat,然后添加到计划任务里,就可以实现一段时间后重启sqlserver服务器了,防止sqlserver经常占用内存过高,导致网页无法打开数据。
net stop sqlserveragent
net stop mssqlserver
echo.wscript.sleep(50000)>s.vbs
cscript //nologo s.vbs
del s.vbs
net start mssqlserver
net start sqlserveragent
收缩sqlserver数据库,清空日志文件
dump transaction [数据库名] with no_log
backup log [数据库名] with no_log
dbcc shrinkdatabase([数据库名])
mysql数据库下实现自动备份并用winrar压缩实现的批处理和php文件
for /d %%i in (*) do d:\php\php5\php.exe -q d:\php\php5\backup.php %%i
backup.php
<?php
if ($argc != 2 || in_array($argv[1], array('--help', '-?'))) {
?>
backup ver 0.01, for win95/win98/winnt/win2000/winxp on i32
copyright (c) 2000 ptker all rights reserved.
this is free software,and you are welcome to modify and redistribute it
under the gpl license
php shell script for the backup mysql database.
usage: <?php echo $argv[0]; ?> <option>
<option> can be database name you would like to backup.
with the --help, or -? options, you can get this help and exit.
<?php
} else {
$dbname = $argv[1];
$dump_tool = "d:\\php\\mysql\\bin\\mysqldump.exe";
$rar_tool = "d:\\program\\winrar\\rar.exe";
$dateml=date("ymd");
$yesday=date('ymd' , strtotime('-6 day'));
@exec("md f:\\sqldata\\mysqlbak\\$dateml");
@rmdir("f:\\sqldata\\mysqlbak\\$yesday");
//@exec("$dump_tool --single-transaction --opt -u root -pxzqcabcd986 $dbname > ./$dbname.sql");
//@exec("$rar_tool a -ag_yyyy_mm_dd_hh_mm f:\\sqldata\\mysqlbak\\{$dateml}\\$dbname.rar $dbname.sql");
@exec("$rar_tool a -ag_yyyy_mm_dd_hh_mm f:\\sqldata\\mysqlbak\\{$dateml}\\$dbname.rar d:\\php\\mysql\\data\\$dbname");
@rmdir($dbname);
echo "backup complete!";
}
?>
复制代码 代码如下:
net stop sqlserveragent
net stop mssqlserver
echo.wscript.sleep(50000)>s.vbs
cscript //nologo s.vbs
del s.vbs
net start mssqlserver
net start sqlserveragent
收缩sqlserver数据库,清空日志文件
复制代码 代码如下:
dump transaction [数据库名] with no_log
backup log [数据库名] with no_log
dbcc shrinkdatabase([数据库名])
mysql数据库下实现自动备份并用winrar压缩实现的批处理和php文件
复制代码 代码如下:
for /d %%i in (*) do d:\php\php5\php.exe -q d:\php\php5\backup.php %%i
backup.php
复制代码 代码如下:
<?php
if ($argc != 2 || in_array($argv[1], array('--help', '-?'))) {
?>
backup ver 0.01, for win95/win98/winnt/win2000/winxp on i32
copyright (c) 2000 ptker all rights reserved.
this is free software,and you are welcome to modify and redistribute it
under the gpl license
php shell script for the backup mysql database.
usage: <?php echo $argv[0]; ?> <option>
<option> can be database name you would like to backup.
with the --help, or -? options, you can get this help and exit.
<?php
} else {
$dbname = $argv[1];
$dump_tool = "d:\\php\\mysql\\bin\\mysqldump.exe";
$rar_tool = "d:\\program\\winrar\\rar.exe";
$dateml=date("ymd");
$yesday=date('ymd' , strtotime('-6 day'));
@exec("md f:\\sqldata\\mysqlbak\\$dateml");
@rmdir("f:\\sqldata\\mysqlbak\\$yesday");
//@exec("$dump_tool --single-transaction --opt -u root -pxzqcabcd986 $dbname > ./$dbname.sql");
//@exec("$rar_tool a -ag_yyyy_mm_dd_hh_mm f:\\sqldata\\mysqlbak\\{$dateml}\\$dbname.rar $dbname.sql");
@exec("$rar_tool a -ag_yyyy_mm_dd_hh_mm f:\\sqldata\\mysqlbak\\{$dateml}\\$dbname.rar d:\\php\\mysql\\data\\$dbname");
@rmdir($dbname);
echo "backup complete!";
}
?>