mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2026-04-26 09:46:00 +03:00
[GH-ISSUE #470] Backup script for SQLite database. Will it work and are they correct? #290
Labels
No labels
SSO
Third party
better for forum
bug
bug
documentation
duplicate
enhancement
future Vault
future Vault
future Vault
good first issue
help wanted
low priority
notes
pull-request
question
troubleshooting
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vaultwarden#290
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @BobWs on GitHub (May 2, 2019).
Original GitHub issue: https://github.com/dani-garcia/vaultwarden/issues/470
I was wondering which one of these scripts is best for backing up my bitwarden database. Script 1 has been converted from a mysql database and script 2 googled and adapted to my preferences.
Script 1:
#!/bin/bash#DIR=/path/to/backup/destination/BACKUP_FILE=/path/to/file/db.sqlite3DATESTAMP=$(date +%Y%m%d%H%M%S)#create backup dir if it does not existmkdir -p ${DIR}#remove all backups except the $KEEP latestsKEEP=5BACKUPS=find ${DIR} -name "sqldump-.gz" | wc -l | sed 's/\ //g'while [ $BACKUPS -ge $KEEP ]dols -tr1 ${DIR}sqldump-.gz | head -n 1 | xargs rm -fBACKUPS=expr $BACKUPS - 1done#list sqlit3 databases and dump eachFILENAME=${DIR}sqldump-${DATESTAMP}.gzcp $BACKUP_FILE $DIR --flush-logs | gzip > $FILENAMEScript 2:
#!/bin/bashBACKUP_FILE="/path/to/file/db.sqlite3"BACKUP_DIR="/path/to/backup/destination/“today=$(date "+%Y-%m-%d")# Less than 31 days old, i.e. 30 days or youngerif find "$BACKUP_FILE" -type f -mtime -31 | grep -q .thenfind "$BACKUP_DIR" -type f -mtime +30 -deletefilast_backup=$(ls -t "$BACKUP_DIR" | head -n 1)if [ ! "$last_backup" ] || ! cmp -s "$BACKUP_FILE" "$BACKUP_DIR/$last_backup"thencp "$BACKUP_FILE" "$BACKUP_DIR/$today.sqlite3@mprasil commented on GitHub (May 2, 2019):
Simply copying file might lead to corrupted backup. (not very likely, but also not the best practice) so keep that in mind. Maybe consider dumping the DB instead as described in the wiki, which also covers backing up other files.
As for rotating backup files, I'd say the second script looks somewhat cleaner although I don't quite see what's the point of
smp -s....if you're going to run the backup daily.@mprasil commented on GitHub (May 16, 2019):
I'm going to close this as the question probably has been answered with the link to wiki. Feel free to reopen if something still isn't clear.
@BobWs commented on GitHub (May 17, 2019):
Okay thanks, at the moment I'm using Hyper Backup to backup Bitwarden on my Synology.
https://www.synology.com/en-global/dsm/feature/hyper_backup