Forum Index  ViceVersa HOME         FAQ and Knowledge Base

 FAQForum FAQ   SearchSearch Forum  RegisterRegister 
 ProfileProfile   Log inLog in 

Different settings for each subdirectory

 
Post new topic   Reply to topic     Forum Index -> Tips, Tricks and More
Author Message
kurt
Guest





PostPosted: Wed May 25, 2005 3:47 pm    Post subject: Different settings for each subdirectory Reply with quote

I was searching for a backup program that could:

make a exact copy of my source directory in a target directory (mirror), including subdirectories can archive files in the target that are removed or overwritten, but only for certain subdirectories include/exclude files, different for each subdirectory.

ViceVersa could do this, ALMOST. Because you can't setup different settings for each source directory, you must create a .fsf file for each directory and run ViceVersa for each file.
With a directory containing more than 1000 subdirectories, this is not very usefull, clicking on each .fsf file.
So I have written a script that can do this automaticly. The javascript that can be run in Windows (use the .js extension) will start at the given source path and backup all files/directories in that path. It will first check of there is a .fsf file in the directory. When that is the case. It will
run ViceVersa with that file to backup the directory with its subdirectories.
When no .fsf file is found. It will backup the files, and then perform the same algorithm for each subdirectory. So you can place a .fsf file in a deeply embedded subdirectory to setup the backup of it different (other include/exclude directories, other archive options, ...).

I have subdirectories with Visual C++ projects that I want to archive, so I have a kind of CVS, but I don't want to backup the huge .pch files.
Other subdirectories contain only documents, datasheets, that I just want to copy and have the latest version.

I now just run the script and it will make a backup of the whole directory, just mirroring or using some special settings, depending of the fact that there is or there isn't a .fsf file.

Maybe ViceVersa can include this principle in a next version, this would improve the speed a lot.

The script is freeware, so here it is.

!! MAKE SURE You setup everthing correct because you can loss files when this isn't the case !!


/[code]** * Name: Backup.js
* Description: Uses ViceVersa to backup directories
* Search each directory for a *.fsf file
* when the file is found, it is executed with ViceVersa
* when the file isn't found, the files in the directory
* are copied with ViceVersa and then the subdirectories
* are search (recurse).
*
* Note: This isn't high speed but that can only be done when
* this could be done by ViceVersa itself.
*
* Author: Kurt Sterckx
* Date: 25 May 2005
**/

/***************************************************************************************

Settings

***************************************************************************************/

/*
sourcepath : Path where <startfolder> is located.
targetpath : Path where <startfolder> must be placed.
startfolder : Folder that must be backed up.
!! Only folder name without path !!
set path with <sourcepath> and <targetpath>
logpath : Path where log file must be placed, only used
when no .fsf file is found. When a .fsf file is
found, the log location in that file is used.
*/
var sourcepath="C:\\";
var targetpath="D:\\Backups";
var startfolder="MyData";
var logpath="C:\\MyLogs\\backup.log";

/*
gui_options : options for ViceVersa to show/hide GUI
sync_options : options for ViceVersa to synchronize directories without .fsf file
log_options : options for logging for directories without .fsf file
*/
var gui_options="/dialogautosync /autoclose";
var sync_options="/comptype:0 /ign2secs /sync:6";
var log_options="/log:\"" + logpath + "\"";

/***************************************************************************************

Main

***************************************************************************************/

/* Create File System Object */
var oFs = new ActiveXObject( "Scripting.FileSystemObject" );

/* Create WSH Shell */
oShell = WScript.CreateObject( "WScript.Shell" );

/* Check running enviroment */
var runincsript = false;
checkrunningincscript();

/* Delete log file */
deletelogfile();

var starttime;
starttime = new Date();
log("Backup starts: " + starttime.toLocaleDateString() + " " + starttime.toLocaleTimeString() + "\n");

/* Run function that search directories */
backupdir(startfolder );

var endtime;
endtime = new Date();
log("Backup ends: " + endtime.toLocaleDateString() + " " + endtime.toLocaleTimeString() + "\n");

var timeittook;

timeittook = new Date(endtime.valueOf() - starttime.valueOf());
log("Backup time: " + timeittook.valueOf() + "ms\n");
log(" " + timeittook.getUTCHours() + ":" + timeittook.getUTCMinutes() + ":" + timeittook.getUTCSeconds() + "\n");

/***************************************************************************************

Functions

***************************************************************************************/

function checkrunningincscript()
{
var name;

name = WScript.Fullname;

name = oFs.GetFileName(name);

if (name.toUpperCase() == "CSCRIPT.EXE")
runincsript = true;
}

function deletelogfile()
{
if (oFs.FileExists(logpath))
oFs.DeleteFile(logpath);
}

function log( texttolog )
{
/* Create log file */
var oLogfile = oFs.OpenTextFile(logpath, 8, true);

if (runincsript)
WScript.echo( texttolog );

oLogfile.write( texttolog );

oLogfile.Close();
}

/* Function to scan directory */
function backupdir( dir )
{
var fsf_file;
var dirpath = sourcepath + "\\" + dir;

log( "Backupdir: " + dir + " (" + dirpath + ")\n");

if (oFs.FolderExists( dirpath ))
{
fsf_file = dirpath + "\\backup.fsf";

if (oFs.FileExists(fsf_file))
{
/* When a .fsf file exits, use that file to backup this directory */
/* the .fsf file must be setup to include the subdirectories */

var rtn = 0;
var command;

command = "\"C:\\Program Files\\ViceVersa Pro\\ViceVersa\" " + fsf_file + " " + gui_options;

log("Run: " + command + "\n");

rtn = oShell.Run(command, 1, true);
log("\n");

if (rtn != 0)
log( "ViceVersa Error : " + rtn + "\n");
}
else
{
/* When no .fsf file exits, copy all files in directory with viceversa */
/* and then recurse to subdirectories */

var rtn = 0;
var command;
var fulltargetpath;

fulltargetpath = targetpath + "\\" + dir;
if (oFs.FolderExists(fulltargetpath))
{
log("Directory exits: " + fulltargetpath + "\n");
}
else
{
log("Create directory: " + fulltargetpath + "\n");

oFs.CreateFolder(fulltargetpath);
}

command = "\"C:\\Program Files\\ViceVersa Pro\\ViceVersa\" ";
command = command + "/source:\"" + dirpath + "\" ";
command = command + "/target:\"" + fulltargetpath + "\" ";
command = command + sync_options + " " + gui_options + " " + log_options;

log("Run: " + command + "\n");

rtn = oShell.Run(command, 1, true);
log("\n");

if (rtn != 0)
log( "ViceVersa Error : " + rtn + "\n");

/* Get Current Folder */
var srcFolder = oFs.GetFolder( dirpath );

/* Get any sub folders to current directory */
var esub = new Enumerator( srcFolder.SubFolders );

/* Loop through sub folder list and scan */
/* through a recursive call to this function */
for(; !esub.atEnd(); esub.moveNext() )
{
var f = oFs.GetFolder( esub.item() );
var fname = oFs.GetFileName(f);

fname = dir + "\\" + fname;

log( "Recursive to : " + fname + "\n");

backupdir( fname );
}
}
}
}[/code]
Back to top
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Tips, Tricks and More All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group
Copyright © TGRMN Software. TGRMN Software products: