diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c584782 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +staging/bitwarden/ diff --git a/backup-bitwarden.env b/backup-bitwarden.env index 8d70b53..9552f7d 100644 --- a/backup-bitwarden.env +++ b/backup-bitwarden.env @@ -1,3 +1,3 @@ ROOT_DIR=/opt/bitwardenrs +ETC_DIR=/etc/bitwardenrs S3_BUCKET=bitwarden.exceede.com -DATABASE_URL=bitwarden diff --git a/backup-bitwarden.sh b/backup-bitwarden.sh index ea2994c..fdbce1d 100755 --- a/backup-bitwarden.sh +++ b/backup-bitwarden.sh @@ -22,7 +22,7 @@ function check_for_hash() { function create_and_upload() { local sum=$1 local backup_file - backup_file="$(date +%Y/%m/backup-%d-%H-%M-%S.tar.gz)" + backup_file="$(date +%Y/%m/${DATABASE_URL}_backup-%d-%H-%M-%S.tar.gz)" echo "Uploading ${backup_file}" tar -zc . | aws s3 cp - "s3://${S3_BUCKET}/${backup_file}" aws s3api put-object --bucket "${S3_BUCKET}" --key "sums/${sum}" @@ -35,13 +35,13 @@ 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 "${dumpfile}" +sudo -u postgres -- pg_dump --no-owner --no-privileges --clean --if-exists --quote-all-identifiers "bitwarden_${DATABASE_URL}" -f "${dumpfile}" "${scriptpath}/pgdump-sort" "${dumpfile}" "sorted.sql" -cp -r "${ROOT_DIR}/data" "./data" -cp "${ROOT_DIR}/.env" "./.env" -cp "${ROOT_DIR}/bitwarden.exceede.com.conf" "./bitwarden.exceede.com.conf" +cp -r "${ROOT_DIR}/data/${DATABASE_URL}" "./data" +cp "${ETC_DIR}/${DATABASE_URL}.conf" "./.env" +cp "${ROOT_DIR}/${DATABASE_URL}.conf" "./${DATABASE_URL}.conf" rm -rf ./data/icon_cache diff --git a/backup-bitwarden.timer b/backup-bitwarden.timer deleted file mode 100644 index 1b542d0..0000000 --- a/backup-bitwarden.timer +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=Runs bitwarden backup on a schedule - -[Timer] -Unit=backup-bitwarden.service -OnCalendar=hourly -Persistent=true - -[Install] -WantedBy=timers.target diff --git a/backup-bitwarden.service b/backup-bitwarden@.service similarity index 68% rename from backup-bitwarden.service rename to backup-bitwarden@.service index b49496a..e308a23 100644 --- a/backup-bitwarden.service +++ b/backup-bitwarden@.service @@ -1,8 +1,9 @@ [Unit] -Description=Backup bitwarden configuration, data, and attachments to S3 +Description=Backup bitwarden (%i) configuration, data, and attachments to S3 [Service] EnvironmentFile=/opt/backup/backup-bitwarden.env +Environment=DATABASE_URL=%i Type=oneshot ExecStart=/opt/backup/backup-bitwarden.sh WorkingDirectory=/opt/backup/staging/bitwarden diff --git a/backup-bitwarden@.timer b/backup-bitwarden@.timer new file mode 100644 index 0000000..ee8a576 --- /dev/null +++ b/backup-bitwarden@.timer @@ -0,0 +1,10 @@ +[Unit] +Description=Runs bitwarden backup (%i) on a schedule + +[Timer] +Unit=backup-bitwarden@%i.service +OnCalendar=hourly +Persistent=true + +[Install] +WantedBy=timers.target