#1 Updated vaultwarden script to keep only 30 backups
This commit is contained in:
parent
c07961a4c8
commit
5e9c23ff05
1 changed files with 15 additions and 3 deletions
|
@ -2,7 +2,9 @@
|
||||||
# Backup script for Vaultwarden in a kubernetes cluster
|
# Backup script for Vaultwarden in a kubernetes cluster
|
||||||
|
|
||||||
BACKUP_DEST="/mnt/PRIVATE_DOCS/BACKUPS/vaultwarden"
|
BACKUP_DEST="/mnt/PRIVATE_DOCS/BACKUPS/vaultwarden"
|
||||||
PASSFILE=./vaultwarden_pass.txt
|
PASSFILE="./vaultwarden_pass.txt"
|
||||||
|
|
||||||
|
BACKUP_FILENAME=vaultwarden-sqlbkp_`date +"%Y%m%d"`.bak
|
||||||
|
|
||||||
# Retrieve container names
|
# Retrieve container names
|
||||||
base_container=$( docker ps --format "{{.Names}}" | grep vaultwarden_vaultwarden )
|
base_container=$( docker ps --format "{{.Names}}" | grep vaultwarden_vaultwarden )
|
||||||
|
@ -13,8 +15,9 @@ set -e
|
||||||
|
|
||||||
# Database backup
|
# Database backup
|
||||||
>&2 echo "Backing up database"
|
>&2 echo "Backing up database"
|
||||||
docker exec --env-file "${PASSFILE}" "${database_container}" pg_dump "vaultwarden" -cwv -h "localhost" -U "vaultwarden" -f /tmp/vaultwarden-sqlbkp_`date +"%Y%m%d"`.bak
|
internal_backup="/tmp/${BACKUP_FILENAME}"
|
||||||
docker cp "${database_container}":/tmp/vaultwarden-sqlbkp_$(date +"%Y%m%d").bak "${BACKUP_DEST}"
|
docker exec --env-file "${PASSFILE}" "${database_container}" pg_dump "vaultwarden" -cwv -h "localhost" -U "vaultwarden" -f "${internal_backup}"
|
||||||
|
docker cp "${database_container}":"${internal_backup}" "${BACKUP_DEST}"
|
||||||
|
|
||||||
# Files backup
|
# Files backup
|
||||||
files=("attachments" "sends" "config.json" "rsa_key.pem" "rsa_key.pub.pem")
|
files=("attachments" "sends" "config.json" "rsa_key.pem" "rsa_key.pub.pem")
|
||||||
|
@ -23,4 +26,13 @@ for file in "${files[@]}"; do
|
||||||
docker cp -a "${base_container}":"/data/${file}" "${BACKUP_DEST}"
|
docker cp -a "${base_container}":"/data/${file}" "${BACKUP_DEST}"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Backup cleanup
|
||||||
|
# Only keep the 30 most recent backups => probably a month worth of backups, seems about right.
|
||||||
|
pushd "${BACKUP_DEST}"
|
||||||
|
rm $( ls -l |
|
||||||
|
grep sqlbkp | # Only cleanup database backups
|
||||||
|
sed -E 's/.*\s([a-z0-9_-]+\.bak)$/\1/' | # Take file part
|
||||||
|
head -n -30 ) # Keep 30 backups
|
||||||
|
popd
|
||||||
|
|
||||||
>&2 echo "Done"
|
>&2 echo "Done"
|
||||||
|
|
Loading…
Reference in a new issue