Initial commit

This commit is contained in:
Marc Koch 2023-02-20 15:14:17 +01:00
commit d2e65f403b
2 changed files with 45 additions and 0 deletions

1
README.md Normal file
View File

@ -0,0 +1 @@
# backup-bitwarden

44
backup-bitwarden Executable file
View File

@ -0,0 +1,44 @@
#! /bin/bash
SOURCE_DIR=/home/marc/docker-homelab/vaultwarden/bw-data
BACKUP_DIR=/home/ssh-backups/bitwarden
BACKUP_USER=ssh-backups
DATETIME=$(date '+%Y-%m-%d_%H%M')
BACKUP_NAME="bw-backup-${DATETIME}"
if [ -d ${SOURCE_DIR} ] && [ -d ${BACKUP_DIR} ]; then
# Create backup directory
mkdir ${BACKUP_DIR}/${BACKUP_NAME}
# Backup database into backup directory
sqlite3 ${SOURCE_DIR}/db.sqlite3 ".backup '${BACKUP_DIR}/${BACKUP_NAME}/db-${DATETIME}.sqlite3'"
# Copy attachments and sends to backup directory
cp -r ${SOURCE_DIR}/attachments $BACKUP_DIR/${BACKUP_NAME}/attachments-${DATETIME}
cp -r $SOURCE_DIR/sends $BACKUP_DIR/${BACKUP_NAME}/sends-${DATETIME}
# change into backup directory
if cd $BACKUP_DIR; then
# tar backup directory
tar czf ${BACKUP_NAME}.tar.gz ${BACKUP_NAME}
# Change file ownership
chown ${BACKUP_USER}. ${BACKUP_NAME}.tar.gz
# Remove backup directory
rm -r ${BACKUP_NAME}
# Remove old files
if [ $(ls -A | wc -l) -gt 3 ]; then
rm -r $(ls -t | tail -n +4)
fi
fi
else
if [ ! -d $SOURCE_DIR ]; then
echo "SOURCE_DIR '${SOURCE_DIR}' is not a directory!"
fi
if [ ! -d $BACKUP_DIR ]; then
echo "'BACKUP_DIR ${BACKUP_DIR}' is not a directory!"
fi
fi