DB_Backup plugin README
Last updated: 2.5.2011, version 1.6.0.4

Contents

  1. Preface
  2. Installation
  3. Configuration
  4. Usage
  5. Limitations

Preface

This plugin is based on the TestPlugin by Dominik Reichl. The main credit goes to him.
I have just used the skelet and modified the body to do what I wanted from it.

This plugin, as its name implies, backs up the database to predefined directories.

Installation

  1. Simply copy the DB_Backup.dll to the directory of KeePass.exe
  2. Start KeePass

Multiple languages - Additional steps:

If you would like DB_Backup to speak multiple languages (the same as KeePass), you should copy the appropriate language from the zip file (YOURLANGUAGE_DB_Backup.plng) also to the directory of KeePass.exe. If you can't find your desired language, I would like to encourage you to make a copy of English_DB_Backup.plng, rename it to YourDesiredLanguage_DB_Backup.plng and start translating the strings in it. After you finish, you can just put it into KeePass' directory.

IMPORTANT: In order for the plugin to speak your language, KeePass has to be able to do it also. Therefore, in a successful setup, you'll see two two language files in KeePass' directory for the same language:
YOURLANGUAGE.lng
YOURLANGUAGE_DB_Backup.plng

Happy translation!

Configuration

A GUI is available for the configuration. To reach the configuration dialog, please click on menus:

Extras / DB Backup Plugin / Set Backup Destination

There you'll be able to define up to 99 destinations. The procedure is that you write/paste/select the full path of the directory into the "Destination" field and hit "ADD". "Remove" deletes a destination from the list. A directory browser button has been added to ease this task.

Environmental variables in the destination are expanded to their respective values. Thus if my username is "PlattFuss" then

"D:\%USERNAME%\KeePassBackup" will be expanded to "D:\PlattFuss\KeePassBackup"

Configruation details

All the configurations are stored in the KeePass.ini file (let it be wherever). Lets have a quick look on the keys used.

DB_Backup.Destination.1 is one of the foremost important parameters.

This key should contain the path to the *directory* where you want to have your databases backed up. A trailing backslash is not needed, but will be handled if present. So the appropriate line in KeePass.ini will look like this:
DB_Backup.Destination.1=C:\MyBackedUpDatabases

or if your directory name contains spaces
DB_Backup.Destination.1=C:\My Backed Up Databases

Multiple destination in the ini file will look like this:
DB_Backup.Destination.1=C:\My Backed Up Databases
DB_Backup.Destination.2=D:\%USERNAME%\KeePassBackup
DB_Backup.Destination.3=F:\USBBackup
...
DB_Backup.Destination.45=Z:\%HOSTNAME%\DB Files

and so on. The maximum number of destinations is 99. This is because of the limitation of the two digit number. If someone out there would want to have more, drop me a note and I will create a special edition of the plugin extra for him :-) Note that the number has to increase sequentially. If there will be a gap, the remaining destinations will be skipped. But you can forget this whole bullshit becasue a simple and intuitive GUI is part of the solution as mentioned above.


Configruation details: INI keys and Command line arguments

It is also possible to define the parameters used by this plugin through the command line. Parameters entered through the command line override the settings in the ini file. The following table lists the parameters, their INI file key name, command line prefix and a short description:

.ini file key CMDLine argument Description
DB_Backup.Destination.N -DB_Backup.dest: Backup destination. N can be between 1 and 99. The cmd param can appear repeatedly.
DB_Backup.ExtPrgPath -db_backup.prog: Full path name of the program to start after backup.
DB_Backup.StartExtPrg implicitly yes, if '-db_backup.prog:' is set If 'True', the app. specified by ExtPrgPath will be executed. Default: False
DB_Backup.KeepXBackups -db_backup.cnt: Number of older backups to keep. Default: 1
DB_Backup.ShowWindow -db_backup.show: If 'True' the window of the external program will be shown, otherwise the program will be started hidden, without a window. Default: False
DB_Backup.BackupOnSave implicitly, if db_backup.dest: is set If 'True', backups will be created after every SAVE operation. Default: True
In previous versions, this parameter was named "DB_Backup.BackupsEnabled"
DB_Backup.BackupOnOpen implicitly, if db_backup.openprfx: is set If 'True', backups will be created before every OPEN operation. Default: False
DB_Backup.PrefixOnOpen -db_backup.openprfx: Prefix of backup file names, that are created just before opening the DB. If backslash is used, the substring to the left of the backslash is considered a directory and will be created if non-existing. Default: "OpenedDBs\Copy_of_"
DB_Backup.PrefixOnSave -db_backup.saveprfx: Prefix of backup file names, that are created right after saving the DB. If backslash is used, the substring to the left of the backslash is considered a directory and will be created if non-existing. Default: "SavedDBs\Backup_of"

-DB_Backup.Dest:<destination>

If the parameter value contains spaces, put the path in double quotes. You may define probably any number of such arguments, although I did not test more than two. It could happend the the length of the command line is somehow limited.

Command line example:

KeePass.exe -DB_Backup.Dest:"c:\Program Files\KeePass\" -DB_Backup.Dest:C:\Backup\%USERNAME%\ -db_backup.cnt:3 -db_backup.prog:"notepad.exe" -db_backup.show:1

IMPORTANT: The first parameter for the external program is always the full path of the backed up file. Thus in the above example, the program "notepad.exe" will be called several times and with the following arguments:

notepad.exe c:\Program Files\KeePass\<BACKUP_FILE_NAME>
notepad.exe C:\Backup\%USERNAME%\<BACKUP_FILE_NAME>

Configruation details: Relative paths

The plugin is able to handle relative paths (You will use something like: 'Backups' instead of a full path, like: 'M:\KeePassDB\Backups'), which comes handy if you want to store your database backups somewhere relative to the 'Current Working Directory'. This directory is usually the KeePass install dir, or the directory of the active database, or something totally different :)

Since we are not able to forecast its actual value, two SEMI-environment variables have been introduced, that are working inside the plugin:

%KEEPASSDIR% - Points always to the directory, from where KeePass was started.
%DBDIR% - Points always to the directory of the actual database.

Using this variables, you can set up relative paths like:

%DBDIR%\Backups\SomeotherNestedDir\BackupSet1
%KEEPASSDIR%\OtherBackup\nesting2\BackupSet2

The advantages are hopefully clear to everyone. You don't have to investigate what is the actual "Current Working Directory" (this is really changing quite often), you just use one of the above variables and the backup will always be created where you wanted it. No matter if your USB key is called E: or X: or T: on different system.

You are free to use these variables in command line parameters, but you should keep in mind that %KEEPASSDIR% and %DBDIR% are SEMI-environmental variables, therefore

echo %DBDIR%\Backups\SomeotherNestedDir\BackupSet1

will only write: \Backups\SomeotherNestedDir\BackupSet1

and sadly, this is, what KeePass would get. Therefore we have to write:

echo %%DBDIR%%\Backups\SomeotherNestedDir\BackupSet1

which would result in: %DBDIR%\Backups\SomeotherNestedDir\BackupSet1

As you can see, unlike other environment variables (which are REAL and expandable by the shell itself), these have to be provided by DOUBLE PERCENT SIGNS (otherwise cmd.exe will expand it to nothing, as it is unaware of its value).

A correct command-line for Keepass is hence:

KeePass.exe -DB_Backup.dest:%APPDATA%\KeePass -DB_Backup.dest:%%DBDIR%%\Backups -db_backup.cnt:3

This is all from the configuration point of view. The rest can be handled from the menu ( enable / disable the automatic backups on save or load).


Usage

If the menu "Extras/DB Backup Plugin/Backups Enabled" is really enabled, the plugin will create a backup of your database whenever you call "Save Database" or "Save Database As.." either by clicking it on the toolbar, or by selecting this function through the menu.

The backup files will be placed in the directory specified in KeePass.ini, in variable DB_Backup.Destination (see part 3. Configuration). The database files will be prefixed with whatever was set in the config dialog or the command line. By default the prefix after saving is Backup_of_, thus if the name of your database is MyKeepassDB.kdb then the backup will be called: Backup_of_MyKeepassDB.kdb-0.

Housekeeping:
If the number of backups to keep is set higher than 1, the previous file with index 0 will be renamed to Backup_of_MyKeepassDB.kdb-1, Backup_of_MyKeepassDB.kdb-1 to Backup_of_MyKeepassDB.kdb-2 and so on.

Renaming and/or overwriting will fail if the existing file will have a "Hidden" or "System" attribute set.

Limitations

The key file can't be backed up and would be anyway a security risk.

Contact

Matyas Bene
notabenem@hotmail.com