|
★☆☆☆☆☆☆☆☆☆ |
积分:285 |
发帖:317 |
登录:2024/3/26 |
注册:2006/6/28 |
|
(1楼)【原创】网站目录备份JScript脚本
用于对指定网站的重要目录和文件进行数据备份。请配合操作系统的计划任务功能使用。 /* 使用方法:
var bak = new BackupClass;
bak.SourceDir = "D:\\web\\www";
bak.TargetDir = "D:\\bak\\www";
// 添加备份目录
bak.AddItem("data");
bak.AddItem("member");
bak.AddItem("templets/default");
// 添加备份文件
bak.AddItem("index.php");
bak.AddItem("tags.php");
bak.AddItem("robots.txt");
bak.Backup(); */
function BackupClass()
{
var me = this;
var arrItem = new Array;
var app = WSH.CreateObject("Shell.Application");
this.AddItem = function(strName)
{
strName = strName.replace(/\\/g, "/").replace(/\/$/, "");
var arr = strName.replace(/\/([^\/]+)$/, "*$1").split("*");
if(arr.length < 2) arr.unshift(".");
arrItem.push(arr);
}
this.Backup = function()
{
me.SourceDir = me.SourceDir.replace(/\//g, "\\");
me.TargetDir = me.TargetDir.replace(/\//g, "\\");
var fld = app.Namespace(me.TargetDir);
var strDir = new Date().toLocaleDateString().replace(/\D(\d)(?!\d)/g, "0$1").replace(/\D/g, "");
fld.NewFolder(strDir);
var bakDir = fld.Items().Item(strDir);
for(var i = 0; i < arrItem.length; i++) Copy(bakDir.Path, arrItem[i]);
//WSH.Echo("OK");
}
function Copy(dir, arr)
{
arr[0] = arr[0].replace(/\//g, "\\");
var strDir = dir + "\\" + arr[0];
strDir = strDir.replace(/\\\.$/, "");
var bakDir = app.Namespace(strDir);
if(!bakDir)
{
var fld = app.Namespace(dir);
if(arr[0] != ".") fld.NewFolder(arr[0]);
bakDir = app.Namespace(strDir);
}
var strSrc = arr[0] + "\\" + arr[1];
strSrc = strSrc.replace(/\.\\/, "");
// 参数“16”表示默认全部覆盖
bakDir.CopyHere(me.SourceDir + "\\" + strSrc, 16);
}
}
|