25 lines
		
	
	
		
			869 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
			
		
		
	
	
			25 lines
		
	
	
		
			869 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
#!/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`
 | 
						|
 | 
						|
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>
 | 
						|
if [ 0 -lt "$(ls $HOME/doc/*.kdbx 2>/dev/null | wc -w)" ]; then
 | 
						|
  echo "Saving KeePassXC databases and database keys"
 | 
						|
  rclone copyto                     \
 | 
						|
    "$HOME/doc/" proton-drive:doc/  \
 | 
						|
    --include "/*.{kdbx,kdbx.key}"
 | 
						|
else
 | 
						|
  echo "No password database found, use the following commands to restore"
 | 
						|
  echo ""
 | 
						|
  echo "rclone copy $RCLONE_REMOTE:doc \"$HOME/doc\" --include \"*.{kdbx,kdbx.key}\""
 | 
						|
  exit 1
 | 
						|
fi
 |