bitwarden-attachment-exporter
bitwarden-attachment-exporter copied to clipboard
How-To Import
Very cool how-to-export guide, thank you for sharing this.
I wonder how to import the same files into bitwarden, after doing a full-restore of the whole database? A Import script would be helpful too for migrations like bitwarden -> own-hosted bitwarden.
I have stitched together a quick way of importing all the attachments. It requires that you have imported the json file first so the items exist in the database:
#!/bin/bash
# Set the path to the parent folder that contains the subfolders
parent_folder="./export/attachments"
# Loop through all subfolders in the parent folder
for item_folder in "$parent_folder"/*; do
# Extract the item ID from the subfolder name
item_id=$(basename "$item_folder")
# Loop through all files in the item folder
for file in "$item_folder"/*; do
# Get the full path of the file
file_path=$(realpath "$file")
# Import the file as an attachment
bw create attachment --file "$file_path" --itemid "$item_id"
done
done
Before you run it you must login with "bw login" and export the session variable. It hasn't been extensively tested, so use with care or as a skeleton for a more complete solution.