Repository navigation
Backup and Restore
All the data of KeyAnyWhere is in the PostgreSQL database, but the database alone is not enough: the secrets in it are encrypted with KEY_CRIPTOGRAFIC, which lives outside it. This page lists what to back up, schedules a daily database dump and shows how to restore it.
Warning
A backup without the same KEY_CRIPTOGRAFIC cannot be read: titles, usernames, passwords, links, notes, category names and 2FA secrets stay encrypted forever. Keep a copy of the key away from the server and away from the backups (see Generating Security Keys).
| What | Where | How often |
|---|---|---|
| The database | PostgreSQL keyanywhere
|
Daily (step 1 below) |
| The environment file, with the keys | /etc/keyanywhere/keyanywhere.env |
Once, and again whenever it changes. Keep it separate from the database backups. |
| Local configuration | /var/www/keyanywhere/config/app_local.php |
Whenever it changes |
| Local plugins, if any |
/var/www/keyanywhere/plugins/ and config/plugins_local.php
|
Whenever they change |
The code itself doesn't need a backup: it is the Git tag you installed.
This step creates a backup folder that only postgres can read and a daily job (cron) that writes a compressed dump at 3 a.m. and deletes dumps older than 14 days. Running as postgres avoids storing a database password anywhere.
sudo install -d -m 700 -o postgres -g postgres /var/backups/keyanywheresudo tee /etc/cron.d/keyanywhere-backup > /dev/null <<'EOF'
# Daily KeyAnyWhere database dump, kept for 14 days.
0 3 * * * postgres pg_dump --format=custom --file=/var/backups/keyanywhere/keyanywhere-$(date +\%F).dump keyanywhere && find /var/backups/keyanywhere -name '*.dump' -mtime +14 -delete
EOFRun a first dump now, by hand, to check that it works:
sudo -u postgres pg_dump --format=custom --file=/var/backups/keyanywhere/keyanywhere-$(date +%F).dump keyanywheresudo ls -lh /var/backups/keyanywhereImportant
A backup on the same disk as the server doesn't survive the loss of the server. Copy /var/backups/keyanywhere to another machine or to object storage (for example with rsync or rclone).
Restoring replaces the current data with the data of the dump. Stop Apache so nobody writes in the meantime, recreate the database, load the dump and start Apache again. Set the file you want to restore first:
KAW_DUMP=/var/backups/keyanywhere/keyanywhere-2026-11-29.dumpsudo systemctl stop apache2sudo -u postgres dropdb --if-exists keyanywhere && sudo -u postgres createdb --owner=kaw --encoding=UTF8 keyanywheresudo -u postgres pg_restore --no-owner --role=kaw --dbname=keyanywhere "$KAW_DUMP"sudo -u www-data kaw-cake cache clear_all && sudo systemctl start apache2Log in and open an entry: if its password shows up, the dump and the key match. On a new server, restore /etc/keyanywhere/keyanywhere.env (with the same KEY_CRIPTOGRAFIC) before testing.
Tip
Test a restore every now and then, on another machine. A backup that was never restored is only a hope.
Source code · Issues · Releases · Packagist · Online demo · Hosted edition
1. Getting started
2. Installing in production
- Overview
- Preparing the Server
- Installing KeyAnyWhere
- File Permissions
- Generating Security Keys
- Environment Variables
- Configuration Files
- Database Setup
- Insecure Password Catalog
- Web Server and HTTPS
- First-Run Setup
3. Operating your installation
4. Using KeyAnyWhere
5. Security
6. Development
7. Extending