Initial import
This commit is contained in:
3
backup-bitwarden.env
Normal file
3
backup-bitwarden.env
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
ROOT_DIR=/opt/bitwardenrs
|
||||||
|
S3_BUCKET=bitwarden.exceede.com
|
||||||
|
DATABASE_URL=bitwarden
|
||||||
12
backup-bitwarden.service
Normal file
12
backup-bitwarden.service
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Backup bitwarden configuration, data, and attachments to S3
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
EnvironmentFile=/opt/backup/backup-bitwarden.env
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart=/opt/backup/backup-bitwarden.sh
|
||||||
|
WorkingDirectory=/opt/backup/staging/bitwarden
|
||||||
|
Slice=backup.slice
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
46
backup-bitwarden.sh
Executable file
46
backup-bitwarden.sh
Executable file
@@ -0,0 +1,46 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
dumpfile="dump.sql.custom"
|
||||||
|
|
||||||
|
tmpdir="$(mktemp -d -p "${PWD}")"
|
||||||
|
|
||||||
|
function check_for_hash() {
|
||||||
|
local ret=0
|
||||||
|
echo "Checking if hash ${1} is present"
|
||||||
|
aws s3 ls "s3://${S3_BUCKET}/sums/${1}" || ret=$?
|
||||||
|
echo "Returned: ${ret}"
|
||||||
|
return $ret
|
||||||
|
}
|
||||||
|
|
||||||
|
function create_and_upload() {
|
||||||
|
local sum=$1
|
||||||
|
local backup_file
|
||||||
|
backup_file="$(date +%Y/%m/backup-%d-%H-%M-%S.tar.gz)"
|
||||||
|
tar -zc . | aws s3 cp - "s3://${S3_BUCKET}/${backup_file}"
|
||||||
|
aws s3api put-object --bucket "${S3_BUCKET}" --key "sums/${sum}"
|
||||||
|
}
|
||||||
|
|
||||||
|
chmod ugo+wX "${tmpdir}"
|
||||||
|
|
||||||
|
pushd "${tmpdir}"
|
||||||
|
|
||||||
|
rm -rf "${dumpfile}"
|
||||||
|
touch "${dumpfile}"
|
||||||
|
chmod ugo+w "${dumpfile}"
|
||||||
|
sudo -u postgres -- pg_dump --no-owner --no-privileges --clean --if-exists --quote-all-identifiers "${DATABASE_URL}" -F plain -f "${dumpfile}"
|
||||||
|
|
||||||
|
cp -r "${ROOT_DIR}/data" "./data"
|
||||||
|
cp "${ROOT_DIR}/.env" "./.env"
|
||||||
|
cp "${ROOT_DIR}/bitwarden.exceede.com.conf" "./bitwarden.exceede.com.conf"
|
||||||
|
|
||||||
|
# remove icon_cache
|
||||||
|
rm -rf ./data/icon_cache
|
||||||
|
|
||||||
|
sum=$(find . -type f -exec md5sum {} + | LC_ALL=C sort | md5sum | cut -d ' ' -f 1)
|
||||||
|
|
||||||
|
check_for_hash "$sum" || create_and_upload "${sum}"
|
||||||
|
|
||||||
|
popd
|
||||||
|
rm -rf "${tmpdir}"
|
||||||
10
backup-bitwarden.timer
Normal file
10
backup-bitwarden.timer
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Runs bitwarden backup on a schedule
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
Unit=backup-bitwarden.service
|
||||||
|
OnCalendar=daily
|
||||||
|
Persistent=true
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
||||||
8
backup.slice
Normal file
8
backup.slice
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Slice for backups
|
||||||
|
DefaultDependencies=no
|
||||||
|
Before=slices.target
|
||||||
|
|
||||||
|
[Slice]
|
||||||
|
CPUQuota=80%
|
||||||
|
MemoryLimit=1G
|
||||||
0
staging/bitwarden/.gitkeep
Normal file
0
staging/bitwarden/.gitkeep
Normal file
Reference in New Issue
Block a user