- Usage
- Examples
- The Inka Actions
- Encrypting passwords
- The Copy Template Action
- The SkyDrive Action
- The configuration file
- Advanced Command File Features
- Tokens
- Advanced Topics
- Missing RoboCopy features
- License
- System Requirements
- Download
- Installation
- Release Notes
The problem is that there is no API for it. Under newer Windows versions you are no longer able to call executables from a Windows Service, which was possible in the past. So I can no longer use Robocopy from a service.
Another requirement I had was to zip up all files changed today. I would first use robocopy to a second location filtering for new files and then zip all files there and then delete them.
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=myuser;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.
stoponerrors Normally if a directory does not exist, the whole command file execution is terminated, you can set this to false to ignore the problem and continue with the next command.
When copying files, they are only copied when the same file does not yet exist at the destination.The InkaPack action has three 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 list of the files in the zip 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 'Encrypting passwords' 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.
pathhandling = Prior to version 2.24 the path recorded in the zip was the full original one from the hard drive where it was zipped. That was hardly ever needed and more often annoying. Since Version 2.24 by default only the path relative to the start folder is recorded in the zip file. This setting can be set to one of the following options:
- path = The full path is recorded, the pre-2.24 behaviour
- folder = The folder structure under the start folder is recorded
- parent = The start folder itself and all folders below are recorded (default)
- none = No path information is recorded.
Any passwords that can be used by Kampot, must be encrypted in the config file.
We are using the Windows built-in encryption. You encrypt your password and store it
in the kampot.config file. Kampot can then decrypt it as long as it runs on the same
computer under the same user account that encrypted it. So if you move computers or
change you account, you have to encrypt the password again.
To encrypt your password, use the program creel.exe that comes with Kampot. Just start it and type your password into the upper text box and click 'Encrypt'. The encrypted text is displayed in the lower textbox and also copied into your clipboard. Just paste the text into the value field in the config file.
Uploads a file to Microsoft SkyDrive online storage service.
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 upload 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. See the 'Encrypting passwords' section for more details.
Only change the settings in the <appSettings> section. The four directories are used as global tokens. The other settings are for specific actions.
Setting ExceptionEmailPreventionPattern Since version 2.71 you can specify a regular expression in this setting. If the error text matches this expression, the error is logged to a file or database, but not emailed.
In some backup scenarios certain files were sometimes locked and an error mail was sent all the file. Specifying the file name in ExceptionEmailPreventionPattern now prevents these emails.
<parameters> <excludefiles>pdb$|dll$|exe$</excludefiles> </parameters> <actions> <inkalist source="C:\code\" /> <inkalist source="C:\docs\" excludefiles="temp$" /> </actions>The first action uses the excludefiles as specified in the parameters section. The second one overrides it.
You use them by wrapping their name in two percent characters:
<actions> <inkalist source="%myTestFolder%foo" /> </actions>
<appSettings> <add key="token_theTestFolder" value="F:\hosts\tools\Kampot\" /> <add key="token_myname" value="Peter" /> </appSettings>All keys in the AppSettings section that begin with token_ are considered global tokens, however to use them in the command files, you only use the second part after the 'token_' bit.
<tokens> <myTestFolder>F:\hosts\tools\Kampot\</myTestFolder> </tokens> <actions> <inkalist source="%myTestFolder%foo" /> </actions>
%time% = the current date and time in the format 20090228T235825 for 28th of February 2009, 11pm 58 minutes 25 seconds. This is useful for creating files with a unique name.
%date% = the current date in the format 20090228 for 28th of February 2009.
%lasttwomonths%, %lastthreemonths% and %lastsixmonths% = These are special token that expand into a yearMonth regular expression. Say we have August 2013, the first one would expand to '2013(07|08)', say we have February 2014, the second one would expand to '(201312|201401|201402)'. This is to match files or folders that are named this way. I needed this because I had to match folders based on their names rather than on the age of the files they contain. (New in version. 2.47)
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 of the command files.
Use tokens on the command line like this:
kampot.exe -token_targetDrive=E kampot.exe -token_myname="Joe Block"The '-token_' is just the identifier for a token, the actually token names here are 'targerDrive' and 'myname'.
[Tokens were added in version 2.13]
After all these application specific tokens have been processed, the final step
in the token substitution is using Windows Environment variables. The have the same
percent sign format anyways. So any found environment variables are replaced with their value.
[Windows Environment token were added in version 2.41]
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.