bitwarden-attachment-exporter icon indicating copy to clipboard operation
bitwarden-attachment-exporter copied to clipboard

How-To Import

Open 768kb opened this issue 3 years ago • 1 comments

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.

768kb avatar Nov 11 '21 06:11 768kb

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.

domingo13 avatar Jan 28 '23 13:01 domingo13