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 automatic filling 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 will automatically start bitwarden on startup.
Visit https://yourdomain/admin to access the management panel.
At this point, bitwarden is set up and ready to use, but I still recommend configuring data backup.

First, install 7Z, which is used to encrypt and package the data before transferring 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 password you want to set for the compressed file.

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

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

Finally, add a cron job to schedule the backup:
0 13 * * * /usr/local/backup/backup.sh
0 22 * * * /usr/local/backup/backup.sh
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.