2022-05-11 13:45:34 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Save (encrypted) password database to cloud storage
|
|
|
|
#
|
|
|
|
# Can be run manually or daily by enabling the corresponding systemd user
|
|
|
|
# service and timer, i.e.
|
|
|
|
#
|
|
|
|
# `systemctl --user enable save-passwddb.service`
|
|
|
|
# `systemctl --user enable save-passwddb.timer`
|
|
|
|
|
2024-06-02 14:06:52 +02:00
|
|
|
RCLONE_REMOTE="proton-drive"
|
|
|
|
|
|
|
|
# Reference: <https://unix.stackexchange.com/questions/100871/in-a-bash-if-condition-how-to-check-whether-any-files-matching-a-simple-wildcard>
|
2023-12-09 20:37:50 +01:00
|
|
|
if [ 0 -lt "$(ls $HOME/doc/*.kdbx 2>/dev/null | wc -w)" ]; then
|
2024-06-02 14:06:52 +02:00
|
|
|
echo "Saving KeePassXC databases and database keys"
|
2024-06-02 14:19:56 +02:00
|
|
|
rclone copyto \
|
|
|
|
"$HOME/doc/" "$RCLONE_REMOTE:doc"/ \
|
|
|
|
--progress \
|
2024-06-02 14:06:52 +02:00
|
|
|
--include "/*.{kdbx,kdbx.key}"
|
2023-06-12 00:25:20 +02:00
|
|
|
else
|
2023-12-09 20:37:50 +01:00
|
|
|
echo "No password database found, use the following commands to restore"
|
|
|
|
echo ""
|
2024-06-02 14:06:52 +02:00
|
|
|
echo "rclone copy $RCLONE_REMOTE:doc \"$HOME/doc\" --include \"*.{kdbx,kdbx.key}\""
|
2023-06-12 00:25:20 +02:00
|
|
|
exit 1
|
|
|
|
fi
|