[GH-ISSUE #938] Backing up database #666

Closed
opened 2026-03-03 02:01:57 +03:00 by kerem · 9 comments
Owner

Originally created by @danielrlutz on GitHub (Mar 30, 2020).
Original GitHub issue: https://github.com/dani-garcia/vaultwarden/issues/938

Hey there!

I'm really enjoying bitwarden_rs but I've come to my end of understanding. Which directory/file is necessary for saving the client's values? Is it possible to replace it and it is all going to work again?

Regards,
Daniel

Originally created by @danielrlutz on GitHub (Mar 30, 2020). Original GitHub issue: https://github.com/dani-garcia/vaultwarden/issues/938 Hey there! I'm really enjoying bitwarden_rs but I've come to my end of understanding. Which directory/file is necessary for saving the client's values? Is it possible to replace it and it is all going to work again? Regards, Daniel
kerem 2026-03-03 02:01:57 +03:00
Author
Owner

@dani-garcia commented on GitHub (Mar 30, 2020):

There's a pretty good description in the wiki: https://github.com/dani-garcia/bitwarden_rs/wiki/Backing-up-your-vault

It mentions backing up the database with the sqlite command, but you can also copy the files like normal as long as the server is stopped before.

<!-- gh-comment-id:606272194 --> @dani-garcia commented on GitHub (Mar 30, 2020): There's a pretty good description in the wiki: https://github.com/dani-garcia/bitwarden_rs/wiki/Backing-up-your-vault It mentions backing up the database with the sqlite command, but you can also copy the files like normal as long as the server is stopped before.
Author
Owner

@danielrlutz commented on GitHub (Mar 30, 2020):

"The files"? Which one would that be? I tried to replace the db.sqlite3 from another database but the client data wasn't there.

<!-- gh-comment-id:606276020 --> @danielrlutz commented on GitHub (Mar 30, 2020): "The files"? Which one would that be? I tried to replace the db.sqlite3 from another database but the client data wasn't there.
Author
Owner

@dennisgerding commented on GitHub (Mar 31, 2020):

I use a small script for backing up my vault. It could be easy for you.

#!/bin/bash

today=`date +%Y%m%d`
todayhuman=`date +"%d-%m-%Y %H:%M:%S"`
random=`head /dev/urandom | tr -dc a-f0-9 | head -c 12 ; echo ''`
workdir=/tmp/bwrs_$random
zipfile=/tmp/bwbackup-$today-$random.tar.gz

mkdir $workdir
mkdir $workdir/bw-data
mkdir $workdir/bw-data/attachments

cp -r /opt/docker/bitwarden_rs/bw-data/attachments/ $workdir/bw-data/
cp /opt/docker/bitwarden_rs/docker-compose.yml $workdir
cp /opt/docker/bitwarden_rs/bw-data/config.json $workdir/bw-data
sqlite3 /opt/docker/bitwarden_rs/bw-data/db.sqlite3 ".backup '$workdir/bw-data/db.sqlite3'"

find $workdir -type f | xargs sha256sum > /tmp/$random-shasum.txt
sha1sum=`cat /tmp/$random-shasum.txt`
cp /tmp/$random-shasum.txt $workdir/shasum.txt
rm /tmp/$random-shasum.txt

cd $workdir
tar -czf $zipfile *

rm -rf $workdir

size=`ls -sh $zipfile`
sha1sumfile=`sha256sum $zipfile`

echo -e "Vault backup of $todayhuman\n\n-- file information --\n$size\n$sha1sumfile\n\n-- archive information (shasum.txt) --\n$sha1sum" | mail -s "[bw_backup] $todayhuman ($random)" my@email.nl -A $zipfile

rm $zipfile
<!-- gh-comment-id:606424798 --> @dennisgerding commented on GitHub (Mar 31, 2020): I use a small script for backing up my vault. It could be easy for you. ``` #!/bin/bash today=`date +%Y%m%d` todayhuman=`date +"%d-%m-%Y %H:%M:%S"` random=`head /dev/urandom | tr -dc a-f0-9 | head -c 12 ; echo ''` workdir=/tmp/bwrs_$random zipfile=/tmp/bwbackup-$today-$random.tar.gz mkdir $workdir mkdir $workdir/bw-data mkdir $workdir/bw-data/attachments cp -r /opt/docker/bitwarden_rs/bw-data/attachments/ $workdir/bw-data/ cp /opt/docker/bitwarden_rs/docker-compose.yml $workdir cp /opt/docker/bitwarden_rs/bw-data/config.json $workdir/bw-data sqlite3 /opt/docker/bitwarden_rs/bw-data/db.sqlite3 ".backup '$workdir/bw-data/db.sqlite3'" find $workdir -type f | xargs sha256sum > /tmp/$random-shasum.txt sha1sum=`cat /tmp/$random-shasum.txt` cp /tmp/$random-shasum.txt $workdir/shasum.txt rm /tmp/$random-shasum.txt cd $workdir tar -czf $zipfile * rm -rf $workdir size=`ls -sh $zipfile` sha1sumfile=`sha256sum $zipfile` echo -e "Vault backup of $todayhuman\n\n-- file information --\n$size\n$sha1sumfile\n\n-- archive information (shasum.txt) --\n$sha1sum" | mail -s "[bw_backup] $todayhuman ($random)" my@email.nl -A $zipfile rm $zipfile ```
Author
Owner

@danielrlutz commented on GitHub (Mar 31, 2020):

Oh, this looks very useful, thanks!

May I ask why you remove the zip file in the end? Isn't that the final backup?
Also, why do you use a random variable? Is it common to use that for temporary directories?

<!-- gh-comment-id:606481015 --> @danielrlutz commented on GitHub (Mar 31, 2020): Oh, this looks very useful, thanks! May I ask why you remove the zip file in the end? Isn't that the final backup? Also, why do you use a random variable? Is it common to use that for temporary directories?
Author
Owner

@dennisgerding commented on GitHub (Mar 31, 2020):

I remove the zipfile because I mail it to myself (my vault is really small in size). I also had some issues in my mail client making a thread of all the mails, adding a random string in it stopped my mail client from making a thread of it all.
As side effect a random string also makes it possible to back up multiple times a day, however also the time could be used for that.

Edit: I also could figure out how to configure that folder in my mail client properly but I'm lazy.

<!-- gh-comment-id:606516035 --> @dennisgerding commented on GitHub (Mar 31, 2020): I remove the zipfile because I mail it to myself (my vault is really small in size). I also had some issues in my mail client making a thread of all the mails, adding a random string in it stopped my mail client from making a thread of it all. As side effect a random string also makes it possible to back up multiple times a day, however also the time could be used for that. Edit: I also could figure out how to configure that folder in my mail client properly but I'm lazy.
Author
Owner

@danielrlutz commented on GitHub (Mar 31, 2020):

Hmm.. so that's still secure because the database's content is encrypted with the master password by the individual users, right?

<!-- gh-comment-id:606527530 --> @danielrlutz commented on GitHub (Mar 31, 2020): Hmm.. so that's still secure because the database's content is encrypted with the master password by the individual users, right?
Author
Owner

@dennisgerding commented on GitHub (Mar 31, 2020):

Yes I believe so.

<!-- gh-comment-id:606586262 --> @dennisgerding commented on GitHub (Mar 31, 2020): Yes I believe so.
Author
Owner

@danielrlutz commented on GitHub (Mar 31, 2020):

Ok, thanks for your help :)

Oh, ehm.. how do you recover from a backup?

<!-- gh-comment-id:606615369 --> @danielrlutz commented on GitHub (Mar 31, 2020): Ok, thanks for your help :) Oh, ehm.. how do you recover from a backup?
Author
Owner

@dennisgerding commented on GitHub (Mar 31, 2020):

In my case I just untar the archive and run docker-compose up -d. That is (for me) possible since it holds the config file, database, attachments and the docker-compose.yml file. Docker will pull the images.

<!-- gh-comment-id:606659969 --> @dennisgerding commented on GitHub (Mar 31, 2020): In my case I just untar the archive and run ```docker-compose up -d```. That is (for me) possible since it holds the config file, database, attachments and the ```docker-compose.yml``` file. Docker will pull the images.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vaultwarden#666
No description provided.