Skip to content

Instantly share code, notes, and snippets.

@harryf
Created January 20, 2020 15:24
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harryf/d23a1ceda84806a099782558fc317adb to your computer and use it in GitHub Desktop.
Save harryf/d23a1ceda84806a099782558fc317adb to your computer and use it in GitHub Desktop.
Quick script for making incremental backups of a keepass database. Combine with Google Drive (or similar) for syncing across devices...
#!/bin/sh
# Cron job
# 15 10 * * * /Users/<username>/bin/backup-passwords
# may need some hacks to get crontab running on OSX
DIR="$HOME/GoogleDrive/passwords"
PASSWDF="$DIR/passwords2.kdbx"
BACKUPF="$DIR/passwords2-"$(date "+%Y%m%d")".kdbx"
if [ ! -e "$PASSWDF" ]
then
>2& echo "$PASSWDF not found"
exit
fi
LASTBKF=$(ls -r $DIR/passwords2-????????.kdbx | head -1)
DIFF=`diff $PASSWDF $LASTBKF`
if [ "$DIFF" != "" ]
then
cp "$PASSWDF" "$BACKUPF"
fi
@harryf
Copy link
Author

harryf commented Jan 20, 2020

Gives you files in the $HOME/GoogleDrive/passwords directory like this, where passwords2.kdbx is the active database

$ ls -t1
passwords2-20200110.kdbx
passwords2.kdbx
passwords2-20191220.kdbx
passwords2-20191216.kdbx
passwords2-20191206.kdbx
passwords2-20191203.kdbx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment