53 lines
1.4 KiB
Bash
53 lines
1.4 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
# All executed commands are printed to stdout
|
|
set -x
|
|
|
|
# Redirect stdout (and stderr to stdout) to a file
|
|
exec 1>/var/log/backup/vaultwarden-backup/vaultwarden-backup-"$(date +%F)".log 2>&1
|
|
|
|
# Abort on nonzero exit status
|
|
set -o errexit
|
|
|
|
# Abort on unbound variable
|
|
set -o nounset
|
|
|
|
# Don't hide errors within pipes
|
|
set -o pipefail
|
|
|
|
# set your API key here
|
|
key=
|
|
|
|
# set your chat id here
|
|
chat_id=
|
|
|
|
function send_message() {
|
|
if ! [ $# -eq 0 ]; then
|
|
curl --silent --show-error --fail --request POST "https://api.telegram.org/$key/sendMessage" --data chat_id="$chat_id" --data text="$1" --output /dev/null
|
|
else
|
|
echo "No argument supplied, please specify the message to send"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
function backup_vaultwarden {
|
|
# Retrieve the date in YYYY-MM-DD format and the timestamp in H-M-S format
|
|
backup_time=$(date +%Y-%m-%d_%I-%M-%S)
|
|
|
|
# Set the destination directory for backups
|
|
destination_directory=/var/local/vaultwarden/backups/${backup_time}
|
|
|
|
# Create the destination directory
|
|
mkdir --parents "$destination_directory"
|
|
|
|
# Save the SQLite 3 database
|
|
if ! sqlite3 /var/lib/vaultwarden/data/db.sqlite3 ".backup $destination_directory/backup.sqlite3"; then
|
|
send_message "[Backup] - Error during Vaultwarden backup, please log in as soon as possible and see what went wrong"
|
|
exit 1
|
|
fi
|
|
|
|
send_message "[Backup] - Vaultwarden has just been backed up"
|
|
}
|
|
|
|
backup_vaultwarden
|