banner
moeyy

moeyy

一条有远大理想的咸鱼。
github
mastodon
email

Bitwarden Automatic Backup

Using virmach or other low-cost VPS providers combined with Dropbox to backup data has the advantage of being extremely cost-effective, costing less than $5 a year! Much better than a NAS without port 80.

~Use bitwarden_rs to set up and backup to Dropbox twice a day to ensure data security.
~In theory, as long as you can run Docker, you can use it. I set it up on a virmach 1c512mb VPS.

~The environment is CentOS 7, as long as you can install Docker.
~The bitwarden app and browser extension can be found in the corresponding app store, and the autofill feature is very convenient. After installation, you can fill in your own domain in the settings.

Then, add the following line to /etc/rc.d/rc.local:
/usr/local/bin/docker-compose -f /opt/bitwarden/docker-compose.yml up -d
This way, bitwarden will automatically start up when the system boots.
You can access the management panel by visiting https://yourdomain/admin.
At this point, bitwarden is set up and ready to use, but I still recommend configuring data backup.

First, let's do something fancy and install 7Z. The purpose is to encrypt the data and then upload it to Dropbox.

wget https://astuteinternet.dl.sourceforge.net/project/p7zip/p7zip/16.02/p7zip_16.02_src_all.tar.bz2
tar -jxvf p7zip_16.02_src_all.tar.bz2
cd p7zip_16.02
make && make install

Set up the backup file.

vi /usr/local/backup/backup.sh

The content is as follows:

#!/bin/bash

#Funciont: Backup website and mysql database
#Author: licess
#Website: https://lnmp.org

Bit_name="bitwarden"
dropboxshell_dir="/usr/local/backup/dropbox_uploader.sh"
drop_dir=/${Bit_name}/$(date +"%Y%m%d%H")
password="wwwwwwww"

#IMPORTANT!!!Please Setting the following Values!
Zip_Dir="/usr/local/bin/7za"
Backup_Home="/opt/bitwarden/"
######~Set Directory you want to backup~######
Backup_Dir=("/usr/local/bitwarden")


#Values Setting END!

OldBackup=${Bit_name}$(date -d -7day +"%Y%m%d%H").7z
Old_DROPBOX_DIR=/${Bit_name}/$(date -d -30day +"%Y%m%d%H")

Backup_Dir()
{
    Backup_Path=$1
    Dir_Name=`echo ${Backup_Path##*/}`
    Pre_Dir=`echo ${Backup_Path}sed 's/'${Dir_Name}'//g'`
    tar zcf ${Backup_Home}bit-${Dir_Name}-$(date +"%Y%m%d%H").tar.gz -C ${Pre_Dir} ${Dir_Name}
}

if [ ! -f ${MySQL_Dump} ]; then  
    echo "mysqldump command not found.please check your setting."
    exit 1
fi

if [ ! -d ${Backup_Home} ]; then  
    mkdir -p ${Backup_Home}
fi


echo "Backup bitwarden files..."
for dd in ${Backup_Dir[@]};do
    Backup_Dir ${dd}
done



echo "compass with 7z..."
${Zip_Dir} a -mhe -p${password} ${Backup_Home}${Bit_name}$(date +"%Y%m%d%H").7z ${Backup_Home}bit-${Dir_Name}-$(date +"%Y%m%d%H").tar.gz
rm -rf ${Backup_Home}bit-${Dir_Name}-$(date +"%Y%m%d%H").tar.gz

echo "upload to dropbox..."
${dropboxshell_dir} upload $Backup_Home/${Bit_name}$(date +"%Y%m%d%H").7z $drop_dir/${Bit_name}$(date +"%Y%m%d%H").7z
${dropboxshell_dir} delete $Old_DROPBOX_DIR

echo "Delete old backup files..."
rm -f ${Backup_Home}${OldBackup}

Replace the password with the desired password for the compressed file.

You need to register for Dropbox (requires email verification) and then go to https://www.dropbox.com/developers/apps to create an app and generate a secret key.

After running dropbox_uploader.sh, enter the secret key.
Run backup.sh once to test if the backup is effective.

Finally, add a cron job to schedule backups to Dropbox:
0 13 * * * /usr/local/backup/backup.sh
0 22 * * * /usr/local/backup/backup.sh
This will backup to Dropbox at 13:00 and 22:00 every day.

From MJJJ: @mmmmmiku

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.