This script is designed to automate the backup process for Vaultwarden sqlite database.
- Overview
- Configuration
- Usage
- Creating a Cron Job for Automated Backup
- Using Rsync for Remote Backups
- Author
Vaultwarden is a self-hosted password manager. This script helps you create and manage backups of your Vaultwarden data to ensure the safety of your password database. Currently the script allows you to keep backups locally or synchronize them via rsync.
Before using the script, you need to configure it by editing the backup.conf
file. Here are the main parameters you should set:
LOCALBACKUPDIR
: The local directory to store all backups.DATADIR
: The Vaultwarden data directory.RETENTION
: The backup retention time in days.
ENABLELOG
: Enable logging to systemd (true or false).BACKUP_ATTACHMENTS
: Set to true to include the attachments folder in the backup.BACKUP_CONFIG_JSON
: Set to true to include theconfig.json
file in the backup.BACKUP_ICON_CACHE
: Set to true to include the icon cache folder in the backup.BACKUP_RSA_KEY
: Set to true to include the RSA keys in the backup.BACKUP_SENDS
: Set to true to include thesends
folder in the backup.ENABLERSYNC
: Enable Rsync (true or false).REMOTEHOST
: The Rsync remote host.REMOTEUSER
: The Rsync remote user.REMOTEPATH
: The Rsync remote path.ENABLESMB
: Enable SMB/CIFS (true or false).REMOTEHOST
: The SMB/CIFS remote host.SMB_USERNAME
: The SMB/CIFS remote user.SMB_PASSWORD
: The SMB/CIFS remote user.REMOTESHARE
: The SMB/CIFS remote path.
-
Clone this repository or download the script files.
git clone https://github.com/jr0w3/Vaultwarden-Sqlite-Backup-script.git && cd Vaultwarden-Sqlite-Backup-script/
-
Configure the
backup.conf
file with your specific settings.nano backup.conf
-
Run the script by executing
./backup.sh
in the terminal../backup.conf
-
The script will perform the backup and, if configured, sync the backup to a remote location.
-
You can schedule this script to run periodically to ensure regular backups of your Vaultwarden data.
You can automate the Vaultwarden backup process by setting up a cron job. Here's how to do it:
-
Open a terminal.
-
Open your user's crontab by running the following command:
crontab -e
-
Add the following line to schedule the execution of the backup script every day at midnight (00:00):
0 0 * * * /path/to/your/script/backup.sh
-
Save and close the text editor.
The cron job is now set up to automatically run the Vaultwarden backup script every day at midnight.
Make sure to adjust the time and frequency as needed. You can use the crontab.guru tool to help generate complex cron expressions if necessary.
After setting up the cron job, the script will run automatically at the specified time, ensuring regular backups of your Vaultwarden data.
If you've configured the ENABLERSYNC
option in your Vaultwarden backup script to use Rsync for remote backups, it's important to ensure that SSH key authentication is set up between your local and remote machines. This will allow the backup process to run without requiring a password input.
Here's how to set up SSH key authentication for Rsync:
-
Generate SSH Keys: If you haven't already done so, you'll need to generate an SSH key pair on your local machine. You can do this with the following command:
ssh-keygen -t rsa
You can leave the passphrase empty for passwordless authentication.
- Copy the Public Key: After generating your SSH key pair, you need to copy the public key to the remote machine. You can use the ssh-copy-id command to do this:
ssh-copy-id user@remote_host
Replace user
with your remote username and remote_host
with the hostname or IP address of the remote machine.
- Test SSH Access: To ensure that SSH key authentication is working correctly, try connecting to the remote machine without a password prompt:
ssh user@remote_host
You should be able to log in without being asked for a password.
- Secure the Private Key: Make sure to keep your private key secure on your local machine, as it provides access to the remote system. Protect it with appropriate file permissions.
Once SSH key authentication is set up, your Rsync command in the backup script will be able to connect to the remote host without requiring a password. This is essential for unattended, automated backups. Make sure to replace user
and remote_host
with your actual username and remote host information.
You need setup ENABLESMB
to true
top enable SMB/CIFS backup.
- Author: Jr0w3
- Release Date: 23/10/2023
If you have any questions or encounter issues with the script, please feel free to create an issue on GitHub for assistance. The author will be happy to help you with any problems you may encounter.