Files
scripts/vaultwarden-backup-helpers/import-from-json.sh
bdm d27e93d220 Track vaultwarden backup and restore scripts
Daily SQLite backup to the NetBackup SMB share plus restore/import/export
helpers.

SMB credentials moved out of the scripts into ~/.smbcredentials (mode 600)
and are passed to smbclient via -A instead of -U "user%pass". This keeps
the password out of version control and out of the process list, where
-U exposes it to any local user through ps.
2026-09-28 06:24:25 -07:00

60 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
# Vaultwarden JSON Import Script
# This script imports a JSON export file into Vaultwarden using the Bitwarden CLI.
#
# Usage: ./import-from-json.sh <email> <input-file.json>
# Example: ./import-from-json.sh user@example.com vaultwarden-export-2026-09-19.json
#
# The master password can be provided via:
# - BW_MASTER_PASSWORD environment variable
# - Interactive prompt
set -euo pipefail
EMAIL="${1:-}"
INPUT_FILE="${2:-}"
VAULTWARDEN_URL="https://vault.bdmurphy.me"
if [ -z "$EMAIL" ] || [ -z "$INPUT_FILE" ]; then
echo "Usage: $0 <email> <input-file.json>"
exit 1
fi
if [ ! -f "$INPUT_FILE" ]; then
echo "ERROR: Input file not found: $INPUT_FILE"
exit 1
fi
# Check if bw CLI is available
if ! command -v bw &> /dev/null; then
echo "ERROR: Bitwarden CLI (bw) not found. Install with: npm install -g @bitwarden/cli"
exit 1
fi
# Configure server URL
bw config server "$VAULTWARDEN_URL" >/dev/null
# Login
echo "Logging in to Vaultwarden as $EMAIL..."
if [ -n "${BW_MASTER_PASSWORD:-}" ]; then
export BW_SESSION=$(bw login "$EMAIL" "$BW_MASTER_PASSWORD" --raw)
else
export BW_SESSION=$(bw login "$EMAIL" --raw)
fi
if [ -z "$BW_SESSION" ] || [ "$BW_SESSION" = "null" ]; then
echo "ERROR: Login failed. Check credentials."
exit 1
fi
echo "Login successful. Importing vault from $INPUT_FILE..."
# Import vault from JSON
bw import --format json --input "$INPUT_FILE" --session "$BW_SESSION"
# Lock the vault
bw lock --session "$BW_SESSION" >/dev/null
echo "Import complete!"
echo "Note: You may need to sync the vault in the web/browser extension."