Skip to content

Instantly share code, notes, and snippets.

@josefandersson
Last active September 16, 2020 11:39
Show Gist options
  • Save josefandersson/ad00ee55285d5ef458ab678fb2a9a37d to your computer and use it in GitHub Desktop.
Save josefandersson/ad00ee55285d5ef458ab678fb2a9a37d to your computer and use it in GitHub Desktop.

Revisions

  1. josefandersson revised this gist Sep 16, 2020. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions backup_bitwarden.sh
    Original file line number Diff line number Diff line change
    @@ -10,13 +10,13 @@

    output="/tmp/bwdata-$(date +"%Y%m%d-%H%M%S").tar.zip.gpg"

    echo "Compressing data folder"
    echo "Compressing data directory"
    tar czfP /tmp/bwdata.tar.zip "$1"

    echo "Encrypting tarball to $2"
    echo "Encrypting tarball to recipient $2"
    gpg --encrypt --recipient "$2" --output "$output" /tmp/bwdata.tar.zip

    echo "Sending backup to backup server"
    echo "Sending encrypted backup to $3"
    scp "$output" "$3"

    echo "Cleanup"
  2. josefandersson revised this gist Sep 16, 2020. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions backup_bitwarden.sh
    Original file line number Diff line number Diff line change
    @@ -10,8 +10,6 @@

    output="/tmp/bwdata-$(date +"%Y%m%d-%H%M%S").tar.zip.gpg"

    [ -f "$output" ] && echo "Removing old encrypted tarball" && rm "$output"

    echo "Compressing data folder"
    tar czfP /tmp/bwdata.tar.zip "$1"

  3. josefandersson revised this gist Sep 16, 2020. 1 changed file with 9 additions and 8 deletions.
    17 changes: 9 additions & 8 deletions backup_bitwarden.sh
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,25 @@
    #!/bin/bash

    # Usage: script <gpg recipient> <ssh login@server>:<target folder>
    # Example: script [email protected] [email protected]:~/backups/
    # Usage: script <bitwarden data directory> <gpg recipient> <ssh login@server>:<target folder>
    # Example: script /home/alice/bwdata [email protected] [email protected]:~/backups/
    # Note: Requires elevated permissions to read all files in bitwarden data folder

    [ -z "$1" ] && echo "No recipient" && exit
    [ -z "$2" ] && echo "No backup server" && exit
    [ -z "$1" ] && echo "No data directory" && exit
    [ -z "$2" ] && echo "No recipient" && exit
    [ -z "$3" ] && echo "No backup server" && exit

    output="/tmp/bwdata-$(date +"%Y%m%d-%H%M%S").tar.zip.gpg"

    [ -f "$output" ] && echo "Removing old encrypted tarball" && rm "$output"

    echo "Compressing data folder"
    tar czfP /tmp/bwdata.tar.zip /home/ghost/bwdata
    tar czfP /tmp/bwdata.tar.zip "$1"

    echo "Encrypting tarball to $1"
    gpg --encrypt --recipient "$1" --output "$output" /tmp/bwdata.tar.zip
    echo "Encrypting tarball to $2"
    gpg --encrypt --recipient "$2" --output "$output" /tmp/bwdata.tar.zip

    echo "Sending backup to backup server"
    scp "$output" "$2"
    scp "$output" "$3"

    echo "Cleanup"
    rm /tmp/bwdata.tar.zip
  4. josefandersson created this gist Sep 16, 2020.
    27 changes: 27 additions & 0 deletions backup_bitwarden.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    #!/bin/bash

    # Usage: script <gpg recipient> <ssh login@server>:<target folder>
    # Example: script [email protected] [email protected]:~/backups/
    # Note: Requires elevated permissions to read all files in bitwarden data folder

    [ -z "$1" ] && echo "No recipient" && exit
    [ -z "$2" ] && echo "No backup server" && exit

    output="/tmp/bwdata-$(date +"%Y%m%d-%H%M%S").tar.zip.gpg"

    [ -f "$output" ] && echo "Removing old encrypted tarball" && rm "$output"

    echo "Compressing data folder"
    tar czfP /tmp/bwdata.tar.zip /home/ghost/bwdata

    echo "Encrypting tarball to $1"
    gpg --encrypt --recipient "$1" --output "$output" /tmp/bwdata.tar.zip

    echo "Sending backup to backup server"
    scp "$output" "$2"

    echo "Cleanup"
    rm /tmp/bwdata.tar.zip
    rm "$output"

    echo "Done"