Skip to content

Instantly share code, notes, and snippets.

@ThinkSalat
Created September 29, 2023 20:25
Show Gist options
  • Save ThinkSalat/96f1f2a1ef5655fd00a2275afe8f50b4 to your computer and use it in GitHub Desktop.
Save ThinkSalat/96f1f2a1ef5655fd00a2275afe8f50b4 to your computer and use it in GitHub Desktop.
Bitwarden backup script
@echo off
:: Set date and time environment variables
for /f %%# in ('wMIC Path Win32_LocalTime Get /Format:value') do @for /f %%@ in ("%%#") do @set %%@
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::
:: User1
::
::BW_CLIENTID= From the api key
::BW_CLIENTSECRET= From the api key
::BW_PASS= Master password of the account
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
set BW_CLIENTID=
set BW_CLIENTSECRET=
set BW_PASS=
bw logout > nul 2> nul
bw login --apikey > nul
for /f %%i in ('bw unlock %BW_PASS% --raw') do set BW_SESSION=%%i
bw export %BW_PASS% --output "Bitwarden Backup %month%-%day%-%year%.json" --format encrypted_json
@echo:
set BW_CLIENTID=
set BW_CLIENTSECRET=
set BW_ORGID=
set BW_PASS=
move "Bitwarden Backup %month%-%day%-%year%.json" "<replace with path to backup>"
:: This makes it so the script only keeps the latest 30 days of backups
ForFiles /p "<replace with path to backup>" /s /d -30 /c "cmd /c del @file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment