| # Synchronization Merge changes made in multiple copies of a database.

- Introduction and Requirements
- Invoking a Synchronization
- Technical Details
- Advanced Synchronization Schemes

## Introduction and Requirements

KeePass 2.x features a powerful, built-in synchronization mechanism. Changes made in multiple copies of a database file can be merged safely.

After synchronizing two files A and B, both A and B are up-to-date (i.e. KeePass saves the merged data to both locations when performing a synchronization).

Requirements.

- If the files to be synchronized are accessible via a protocol that KeePass supports by default (e.g. files on a local hard disk or a network share, FTP, HTTP, HTTPS, WebDAV, ..., see the page 'Loading/Saving From/To URL' for details), then no plugins/extensions are required.
- If one of the files to be synchronized should be accessed via SCP, SFTP or FTPS, you need the IOProtocolExt plugin, which adds support for these protocols to KeePass.
- If one of the files to be synchronized is stored in a cloud storage: for most cloud storages, there is an integration with the local file system available (i.e. you can access your stored files using Windows Explorer). For example, Dropbox, Microsoft OneDrive and Google Drive provide such an integration. If such an integration is available, it is recommended that you access your database file this way; this often works better than accessing it via a protocol like FTP or WebDAV. If no such integration is available and your cloud storage also is not accessible via a standard protocol, a specialized KeePass plugin for this cloud storage might be available.

## Invoking a Synchronization

There are multiple ways how a synchronization can be invoked:

- Manually. A synchronization can be started manually by navigating to 'File' → 'Synchronize' and clicking 'Synchronize with File' or 'Synchronize with URL' (depending on whether the file to be synchronized with is stored on a local drive / network share or on a server accessible via a URL). If you've previously opened or synchronized with the target file, you can also simply point on 'Recent Files' (in the 'Synchronize' menu) and select the file. Manual synchronization is only possible when the currently opened database is a local file (files on a network share are here considered to be local files); when you've opened a file from a server using a URL, the 'Synchronize' menu is disabled.
- Command 'Save'. When invoking the 'Save' command, KeePass checks whether the file on disk/server has been modified while you were editing it. If it has been modified, KeePass prompts whether you want to overwrite or synchronize with the file. Note this applies only to the 'Save' command, not the 'Save As' command. See the page 'Multiple Users' for details (section 'KeePass 2.x: Synchronize or Overwrite').
- Triggers. In more complex situations you can use the synchronization trigger action. See the page 'Triggers' for details.
- Scripting. In order to perform a synchronization without opening KeePass, the synchronization command of KPScript can be used. See the KPScript help page 'Single Command Operations' for details.

## Technical Details

The synchronization algorithm is rather complex and it would take many pages to describe in detail how it is working. Developers interested in this can have a look into the KeePass source code. Here are the most important properties of the synchronization algorithm:

- In order to decide which copy of an object is the latest one, KeePass mainly uses the last modification time of the object (which KeePass updates automatically each time the object is changed).
- The synchronization is performed on entry level. This e.g. means that a combination of user name / password is always consistent (synchronization on field level will not be implemented, because combinations could become inconsistent with this).
- In case of parallel updates and collisions, KeePass tries to store all information in an appropriate place. For example, when you have an entry E in a database A, make a copy B of A, change E in B, change E in A, and synchronize A and B, then E in A is treated as current and the changes made to E in B are stored as a history entry of E (see the tab page 'History' in the entry dialog), i.e. the changes made in B are not lost.

## Advanced Synchronization Schemes

- Local↔Master Synchronization.
  A synchronization scheme that prevents data loss when database files are overwritten by other applications (e.g. cloud storage service software), using a trigger.
- Plugins.
  There are plugins for more complex synchronization schemes, for example to synchronize only a subset of the entries.