Skip to content

Instantly share code, notes, and snippets.

@Timeraa
Last active March 3, 2024 12:43
Show Gist options
  • Save Timeraa/34760a5c08d3ed685b95fc65dc0450b5 to your computer and use it in GitHub Desktop.
Save Timeraa/34760a5c08d3ed685b95fc65dc0450b5 to your computer and use it in GitHub Desktop.
Bitwarden On-Premise Backup script

Small Backup script for Bitwarden On-Premise installations which creates a backup zip file of the bwdata folder into a backup dir.

The first input is the backup directory, second is the bwdata directory. It also only keeps the last 7 days by default, can be changed in the file directly or with the third argument.

#!/bin/bash
# Check if backup directory and source directory are specified
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Error: Backup directory and source directory must be specified."
exit 1
fi
# Define the backup directory
BACKUP_DIR="$1"
# Define the source directory
SOURCE_DIR="$2"
# Check if backup directory and source directory exist
if [ ! -d "$BACKUP_DIR" ]; then
echo "Error: Backup directory $BACKUP_DIR does not exist."
exit 1
fi
if [ ! -d "$SOURCE_DIR" ]; then
echo "Error: bwdata directory $SOURCE_DIR does not exist."
exit 1
fi
# Define the number of days to keep backups
DAYS_TO_KEEP="${3:-7}"
# Create a backup
cd $SOURCE_DIR && zip -r "$BACKUP_DIR/bwdata_$(date +%Y%m%d_%H%M%S).zip" .
# Delete backups older than DAYS_TO_KEEP days
find $BACKUP_DIR -type f -mtime +$DAYS_TO_KEEP -name 'bwdata_*.zip' -exec rm {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment