The problem is that there is no API for it and that under newer Windows Version you are no longer suppose to call executables from a Windows Service.
So I wrote my own basic Robocopy clone and added some more features.
Kampot.exe is a command line tool, the only parameter it takes is the name of a 'Kampot Command file' which is a bit like the Robocopy job file. The command file is XML based and has one or multiple actions to be performed. For details about the format see the examples below.
kampot.exe command file [-v] [-s] [-r] [-f] -v verbose, show lots of information during execution -s silent, don't show any information during execution -r report, don't show the report at the end of the execution -f files, list the affected files at the end of the executionAll four switches just affect what is displayed on the command line. All configuration of the actual execution is done in the command files or the kampot.config configuration file.
Some of the things you see in the examples are described below in the Advanced Command File Features section.
<?xml version="1.0" ?> <kampot version="2.0"> <actions> <inkapack source="%data%/Code" destination="%working%backup/RecentCode_%time%.zip" excludefiles="pdb$|dll$|exe$|suo$|user$" excludefolders="Backup|obj|debug|logs|temp|\.svn" encrypt="true" age="15" size="-200" recursive="true" reportlevel="1" updatepackage="false" /> <skydrive file="%last%" rootfolder="Backup" folder="Code" /> </actions> </kampot>- Zip files in the code folder under the data directory as defined in the global config file.
- The zip file will be in the working directory/backup/ and the file name has the current time
- exclude any files with the extenions: .pdb, .dll, .exe, .suo, .user
- exclude a whole bunch of folder names
- encrypt the zip file.
- Only zip files less than 15 hours old
- Only zip files less than 200kb in size
- Include subdirectories
- Use a report level of 1
- Do not add to an existing zip file with the same name
- Upload the file just zipped to skydrive.live.com into the location /Backup/Code/
<?xml version="1.0" ?> <kampot version="2.0"> <actions> <inkadelete source="d:\logs\" age="-240" /> </actions> </kampot>- Delete all files under D:\logs and subdirectories (default)
- they must be older than 240 hours or 10 days.
<connectionStrings> <add name="Main" connectionString="Data Source={%server%};Initial Catalog={%database%};user=webuser;pwd=*********"/> </connectionStrings>and then use a CopyTemplate Action:
<?xml version="1.0" ?> <kampot version="1.0"> <actions> <copytemplate source="%data%\master_web.config" destination="C:\inetpub\wwwroot\web.config" > <token name="server" value="db01" /> <token name="database" value="Dev-Database" /> </copytemplate> </actions> </kampot>For the other databases, I have different command files. You can have an unlimited number of tokens defined.
InkaList: List files according to the specified filters
InkaCopy: Copies files according to the specified filters
InkaPack: Zips files according to the specified filters
InkaDelete: Deletes files according to the specified filters
They all share a common set of attributes which define how they work:
source = The source directory for the files you want to process.
destination = The destination, a folder for InkaCopy, a file for InkaPack and not relevant for InkaList and InkaDelete.
excludefiles = exclude files whose filename match the expression. This looks at the
filename only not the path. A common expression is exe$ which means any filename that ends in exe.
excludefolders = exclude folders whose names that match the expression, this tests only a single folder name not a full path. However it tests all folders in the path beginning at the top. If you have something like C:\myData\temp\word\letter\ and the expression is temp if will not even look anywhere below C:\myData\temp\.
excludepath = excludes files whose full absolute file names match the expression. This
compares the full path rather than a single file name or folder name.
If you want to exclude images but only if they are somewhere under a temp directory, you
should use: temp.+(jpg$)|(png$)|(gif$) The .+ stands for any number of any characters.
includefiles = only file names matching this expression are included. This is an inclusion rule and looks at file names only. If this doesn't exist or is empty, all files will be processed.
recursive = The allowed values are 'true' and 'false' and the default is true. If set to 'false' only the initial folder is processed without traversing into subdirectories.
age = Exclude files that are older or newer a certain number of hours. -10 includes all files that are older than 10 hours. 24 includes all files that have been changed in the last 24 hours. 0 ignores the age of the file.
size = Exclude files that are smaller or bigger than a certain number of kBytes -10 includes all files that are smaller then 10kb, 1000 includes all files that are bigger than 1000kb. 0 ignores the size of the file.
When copying files, they are only copied when the same file does not yet exist at the destination.The InkaPack action has two additional attributes:
encrypt = The allowed values are 'true' and 'false'. Default is false, when set to 'true' the zip file is encrypted with an AES256 algorithm. You can view the content of the file in Windows Explorer, but to extract the content you need a tool that supports this decryption such as WinZip or 7Zip. The password for the encryption has to be specified in kampot.config in the setting 'ContentPassword'. It has to be encrypted, see at the Skydrive Action below for more details.
updatepackage = The allowed values are 'true' and 'false'. Default is false, if set to 'true' the files are added to a file with the same name if it exists, if set to 'false' that file will be deleted and a new file will be created.
The attibutes are:
file = The single file that should be uploaded. The %last% token is often used here to reference a file created by a previous action.
rootfolder = The name of the folder below the root of your SkyDrive. This has to be specified.
folder = The name of the folder on the second level. If empty the file is uploaded into the folder specified in rootfolder. There is currently no way to uploads files into lower levels.
In addition two settings are required in kampot.config
SkyDriveUserName = Your username for Windows Live.
SkyDrivePassword = Your Windows Live password. This has to be present in an encrypted form.
To encrypt your password use kampot.exe like this:kampot.exe -password:"mypassword"or in Powershell:
kampot.exe "-password=mypassword"The encrypted password is copied into the Windows Clipboard and you can then paste it into the kampot.config file. The decryption works only on the same computer and for the same user who encrypted it. If you are moving machines or accounts, you have to encrypt it again.
Only change the settings in the <appSettings> section. The four directories are used as global tokens. The other settings are for specific actions.
<parameters> <excludefiles>pdb$|dll$|exe$</excludefiles> </parameters> <actions> <inkalist source="C:\code\" /> <inkalist source="C:\docs\" excludefiles="temp$" /> </actions>The first action used the excludefiles as specified in the parameters section. The second one overrides it.
Global tokens: %tokenname%
There are a fixed number of these and they are replaced with a value taken from the global configuration file:
%folder1% = appSettings: CustomFolder1
%folder2% = appSettings: CustomFolder2
%working% = appSettings: WorkingDirectory
%data% = appSettings: DataDirectory
Local tokens: %tokenname%
These are defined in the command file like this:
<tokens> <myTestFolder>F:\hosts\tools\Kampot\</myTestFolder> </tokens>Now they can be used in action node like this:
<actions> <inkalist source="%myTestFolder%foo" /> </actions>Other Tokens:
%last% = refers to file created by the previous action. Not all actions create a file so this may be empty.
%time% = the current date and time in the format 20090228T235825 for 28th of Feburary 2009, 11pm 58 minutes 25 seconds. This is useful for creating files with a unique name.
Sometimes you need a similar command file for two operations. You can now supply tokens on the command line, they are handled just like the tokens you specify in the tokens section in the command files.
Use tokens on the command line like this:
kampot.exe -%tokenname%=tokenvalue
[This feature is new in version 2.11]
Use Kampot as a Service - Rather than starting it from the command line with the command file as a parameter you run it as a service and drop the command files into a directory. I use this on web servers where web applications drop command files to perform actions that they are normally not allowed to.
Use the API - Both the command line tool and the service are just clients to the Kampot API, if you are using .net you can use the API directly with or even without command files.
Write your own Action Provider - Each action is executed by a provider. Kampot can be extended by adding more providers which then can handle new actions.
Documentation about these topics is coming later. If you are interested, please let me know.- No Mirror mode (deleting extra files at the destination)
- No transfer of NTFS ACLs
- No robust copy (restart after failure)
Some example command files are included.