From 89673bbce861af3353e6bebe863879b8f58eab52 Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Tue, 9 May 2023 01:22:44 -0700 Subject: [PATCH] Update backup-keepassxc-db.sh --- backup-keepassxc-db.sh | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/backup-keepassxc-db.sh b/backup-keepassxc-db.sh index 15f2f9e..8af4cd7 100755 --- a/backup-keepassxc-db.sh +++ b/backup-keepassxc-db.sh @@ -1,4 +1,18 @@ #!/usr/bin/env zsh + +(( ${#} < 1 )) && { echo 'Device name is required'; exit 1 } + +local devdir="${HOME}/nextcloud/KeePassXC/${2}" + +if ! [ -d "${devdir}" ]; then + mkdir "${devdir}" || exit 1 +fi + +# Remove files older than 30 days (files modified more than 30 days ago) +find "${devdir}" -depth -mtime +30 -delete + local datetime="$(date +'d%d-%m-%Y_t%H-%M-%S')" local filename="keepassxc-db-backup-${datetime}.tar.gz" -tar -caf "${HOME}/nextcloud/KeePassXC/${filename}" "${HOME}/.keepassxc" +tar -caf \ + "${devdir}/${filename}" \ + "${HOME}/.keepassxc"