From aaf9ecfc1d2882a1534fc6db43f00cc69758a615 Mon Sep 17 00:00:00 2001 From: ZoopaMario Date: Sun, 29 Dec 2024 15:08:09 +0100 Subject: [PATCH] Refactor code to make linter runs succeed This commit refactors the codebase in order to make the shellcheck workflow pass. --- .forgejo/workflows/lint-bash.yml | 23 +++++++++++++++---- cryptpad/cryptpad-backup.sh | 38 ++++++++++++------------------- duplicati/duplicati-backup.sh | 30 ++++++++---------------- forgejo/forgejo-backup.sh | 26 +++++++-------------- full-backup.sh | 2 +- immich/immich-backup.sh | 37 +++++++++++------------------- nextcloud/nextcloud-backup.sh | 37 +++++++++++------------------- portainer/portainer-backup.sh | 30 ++++++++---------------- vaultwarden/vaultwarden-backup.sh | 29 ++++++++--------------- 9 files changed, 95 insertions(+), 157 deletions(-) diff --git a/.forgejo/workflows/lint-bash.yml b/.forgejo/workflows/lint-bash.yml index eac4806..d92d92a 100644 --- a/.forgejo/workflows/lint-bash.yml +++ b/.forgejo/workflows/lint-bash.yml @@ -18,14 +18,27 @@ jobs: - name: Checkout Code uses: https://code.forgejo.org/actions/checkout@v4 with: - fetch-depth: 0 # Fetch the entire history to avoid REST API reliance + fetch-depth: 0 - name: Install ShellCheck run: | apt-get update && apt-get install -y shellcheck - - - name: Lint Bash Scripts + + - name: Find Shell Scripts + id: find-scripts run: | - echo "Linting Bash scripts..." - find . -name '*.sh' -print0 | xargs -0 shellcheck + echo "Searching for shell scripts..." + find . -name '*.sh' -print0 > shell-scripts.list + + - name: Run ShellCheck in Script Directories + run: | + echo "Running ShellCheck in each script's directory..." + while IFS= read -r -d '' script; do + echo "Checking $script" + script_dir=$(dirname "$script") + script_name=$(basename "$script") + # Change to the script's directory and run ShellCheck + (cd "$script_dir" && shellcheck -x "$script_name") + done < shell-scripts.list + diff --git a/cryptpad/cryptpad-backup.sh b/cryptpad/cryptpad-backup.sh index 537743d..86007c7 100755 --- a/cryptpad/cryptpad-backup.sh +++ b/cryptpad/cryptpad-backup.sh @@ -1,24 +1,14 @@ #!/bin/bash SCRIPT_ABS_LOCATION=$(realpath "$(dirname "${0}")") -source $SCRIPT_ABS_LOCATION/cryptpad-backup.env -source $SCRIPT_ABS_LOCATION/../logger.sh +source "$SCRIPT_ABS_LOCATION/cryptpad-backup.env" +source "$SCRIPT_ABS_LOCATION/../logger.sh" # Container Names CONTAINER="cryptpad" BACKUP_CONTAINER="duplicati" SOURCE_DIR="/mnt/data/cryptpad" -BACKUP_DESTINATION="$BACKUP_DESTINATION" -BACKUP_ENCR_PASSPHRASE="$BACKUP_ENCR_PASSPHRASE" - -# Cloud Storage Authentication -SFTP_USERNAME="$SFTP_USERNAME" -SFTP_PASSWORD="$SFTP_PASSWORD" -SFTP_FINGERPRINT="$SFTP_FINGERPRINT" - -# Log file -LOG_FILE="$SCRIPT_ABS_LOCATION/cryptpad-backup.log" # Cleanup inactive and archive files log "Cleaning up inactive accounts and files to save space..." @@ -33,20 +23,20 @@ docker exec cryptpad \ # Backup all files to target destination log "Backing up cryptpad files and database..." -docker exec $BACKUP_CONTAINER \ - duplicati-cli backup ssh://$BACKUP_DESTINATION \ - $SOURCE_DIR/data \ - $SOURCE_DIR/datastore \ - $SOURCE_DIR/block \ - $SOURCE_DIR/blob \ - $SOURCE_DIR/config/config.js \ - $SOURCE_DIR/customize \ - $SOURCE_DIR/customize.dist \ +docker exec "$BACKUP_CONTAINER" \ + duplicati-cli backup "ssh://$BACKUP_DESTINATION" \ + "$SOURCE_DIR/data" \ + "$SOURCE_DIR/datastore" \ + "$SOURCE_DIR/block" \ + "$SOURCE_DIR/blob" \ + "$SOURCE_DIR/config/config.js" \ + "$SOURCE_DIR/customize" \ + "$SOURCE_DIR/customize.dist" \ --backup-name="$CONTAINER backup" \ --keep-versions=7 \ - --auth-username=$SFTP_USERNAME \ - --auth-password=$SFTP_PASSWORD \ - --passphrase=$BACKUP_ENCR_PASSPHRASE \ + --auth-username="$SFTP_USERNAME" \ + --auth-password="$SFTP_PASSWORD" \ + --passphrase="$BACKUP_ENCR_PASSPHRASE" \ --ssh-fingerprint="$SFTP_FINGERPRINT" \ --prefix="cryptpad" || { log "Error: Failed to backup cryptpad files and database."; exit 1; } log "cryptpad backup completed successfully." diff --git a/duplicati/duplicati-backup.sh b/duplicati/duplicati-backup.sh index fc7b745..376a7e2 100755 --- a/duplicati/duplicati-backup.sh +++ b/duplicati/duplicati-backup.sh @@ -1,35 +1,22 @@ #!/bin/bash SCRIPT_ABS_LOCATION=$(realpath "$(dirname "${0}")") -source $SCRIPT_ABS_LOCATION/duplicati-backup.env -source $SCRIPT_ABS_LOCATION/../logger.sh - -# Container Name -CONTAINER="duplicati" +source "$SCRIPT_ABS_LOCATION/duplicati-backup.env" +source "$SCRIPT_ABS_LOCATION/../logger.sh" SOURCE_DIR="/mnt/data/duplicati" -SSH_DESTINATION="$SSH_DESTINATION" -BACKUP_ENCR_PASSPHRASE="$BACKUP_ENCR_PASSPHRASE" - -# Cloud Storage Authentication -SSH_USERNAME="$SSH_USERNAME" -SSH_PASSWORD="$SSH_PASSWORD" -SSH_KEY="$SSH_KEY" # Set default values for parameters MAX_BACKUPS=7 BACKUP_FOLDER="" -# Log file -LOG_FILE="$SCRIPT_ABS_LOCATION/duplicati-backup.log" - # Override default values with command-line arguments while getopts ":f:h:u:p:m:b:" opt; do case $opt in f) SOURCE_DIR="$OPTARG";; h) SSH_DESTINATION="$OPTARG";; u) SSH_USERNAME="$OPTARG";; - p) SSH_PASSWORD="$OPTARG";; + p) SSH_KEY="$OPTARG";; m) MAX_BACKUPS="$OPTARG";; b) BACKUP_FOLDER="$OPTARG";; \?) echo "Invalid option: -$OPTARG"; exit 1;; @@ -37,22 +24,23 @@ while getopts ":f:h:u:p:m:b:" opt; do done # Create a temporary file for the encrypted archive +# shellcheck disable=SC2015 TMP_FILENAME=duplicati_db-$(date +"%Y%m%d").bak && -TMP_FILEPATH=$SCRIPT_ABS_LOCATION || { log "Error: Failed to create a temporary file."; exit 1; } +TMP_FILEPATH="$SCRIPT_ABS_LOCATION" || { log "Error: Failed to create a temporary file."; exit 1; } # Create the encrypted archive using tar and openssl log "Compressing and excrypting the Duplicati Databases" -sudo tar -czf - "$SOURCE_DIR" | openssl enc -aes-256-cbc -pbkdf2 -pass pass:$BACKUP_ENCR_PASSPHRASE > $TMP_FILEPATH/$TMP_FILENAME || { log "Error: Failed to create encrypted archive."; exit 1; } +sudo tar -czf - "$SOURCE_DIR" | openssl enc -aes-256-cbc -pbkdf2 -pass "pass:$BACKUP_ENCR_PASSPHRASE" > "$TMP_FILEPATH/$TMP_FILENAME" || { log "Error: Failed to create encrypted archive."; exit 1; } # Connect to the backup host and count the number of existing backups log "Fetching number of backups in destination folder" -EXISTING_BACKUPS=$(ssh $SSH_USERNAME@$SSH_DESTINATION -p 23 -i $SSH_KEY "ls" | sudo wc -l) || { log "Error: Failed to count existing backups."; exit 1; } +EXISTING_BACKUPS=$(ssh "$SSH_USERNAME@$SSH_DESTINATION" -p 23 -i "$SSH_KEY ls" | sudo wc -l) || { log "Error: Failed to count existing backups."; exit 1; } # Remove old backups if there are too many -if (( $EXISTING_BACKUPS > $MAX_BACKUPS )); then +if (( EXISTING_BACKUPS > MAX_BACKUPS )); then log "Removing old backups in order to save space" - ssh $SSH_USERNAME@$SSH_DESTINATION -p 23 -i $SSH_KEY "ls -t $BACKUP_FOLDER | tail -n +$((MAX_BACKUPS+1)) | xargs rm" || { log "Error: Failed to remove old backups."; exit 1; } + ssh "$SSH_USERNAME@$SSH_DESTINATION" -p 23 -i "$SSH_KEY ls -t $BACKUP_FOLDER | tail -n +$((MAX_BACKUPS+1)) | xargs rm" || { log "Error: Failed to remove old backups."; exit 1; } fi # Transfer the encrypted archive to the backup host using scp diff --git a/forgejo/forgejo-backup.sh b/forgejo/forgejo-backup.sh index 8447fa2..d61f592 100755 --- a/forgejo/forgejo-backup.sh +++ b/forgejo/forgejo-backup.sh @@ -1,24 +1,14 @@ #!/bin/bash SCRIPT_ABS_LOCATION=$(realpath "$(dirname "${0}")") -source $SCRIPT_ABS_LOCATION/forgejo-backup.env -source $SCRIPT_ABS_LOCATION/../logger.sh +source "$SCRIPT_ABS_LOCATION/forgejo-backup.env" +source "$SCRIPT_ABS_LOCATION/../logger.sh" # Container Names APP_CONTAINER="forgejo" BACKUP_CONTAINER="duplicati" SOURCE_DIR="/mnt/data/forgejo" -BACKUP_DESTINATION="$BACKUP_DESTINATION" -BACKUP_ENCR_PASSPHRASE="$BACKUP_ENCR_PASSPHRASE" - -# Cloud Storage Authentication -SFTP_USERNAME="$SFTP_USERNAME" -SFTP_PASSWORD="$SFTP_PASSWORD" -SFTP_FINGERPRINT="$SFTP_FINGERPRINT" - -# Log file -LOG_FILE="$SCRIPT_ABS_LOCATION/forgejo-backup.log" # Stop forgejo container log "Stopping forgejo container..." @@ -28,18 +18,18 @@ docker stop $APP_CONTAINER || { log "Error: Failed to stop forgejo."; exit 1; } log "Backing up forgejo files (including the SQLite database)..." docker exec $BACKUP_CONTAINER \ duplicati-cli backup \ - ssh://$BACKUP_DESTINATION \ - $SOURCE_DIR \ + "ssh://$BACKUP_DESTINATION" \ + "$SOURCE_DIR" \ --backup-name="forgejo backup" \ --keep-versions=7 \ - --auth-username=$SFTP_USERNAME \ - --auth-password=$SFTP_PASSWORD \ - --passphrase=$BACKUP_ENCR_PASSPHRASE \ + --auth-username="$SFTP_USERNAME" \ + --auth-password="$SFTP_PASSWORD" \ + --passphrase="$BACKUP_ENCR_PASSPHRASE" \ --ssh-fingerprint="$SFTP_FINGERPRINT" \ --prefix="forgejo" || { log "Error: Failed to backup forgejo files and database."; exit 1; } # Turn off Maintenance Mode log "Starting forgejo container..." -docker start $APP_CONTAINER || { log "Error: Failed to start forgejo container."; exit 1; } +docker start "$APP_CONTAINER" || { log "Error: Failed to start forgejo container."; exit 1; } log "Forgejo backup completed successfully." diff --git a/full-backup.sh b/full-backup.sh index f47168d..56b7202 100755 --- a/full-backup.sh +++ b/full-backup.sh @@ -8,7 +8,7 @@ declare -a apps=("cryptpad" "immich" "duplicati" "nextcloud" "vaultwarden" "forg # Function to execute the backup script for each application backup_app() { local app=$1 - $SCRIPT_ABS_LOCATION/$app/${app}-backup.sh + "$SCRIPT_ABS_LOCATION/$app/${app}-backup.sh" } # Iterate over each app in the array and call the backup function diff --git a/immich/immich-backup.sh b/immich/immich-backup.sh index 96931d0..975a831 100755 --- a/immich/immich-backup.sh +++ b/immich/immich-backup.sh @@ -1,11 +1,10 @@ #!/bin/bash SCRIPT_ABS_LOCATION=$(realpath "$(dirname "${0}")") -source $SCRIPT_ABS_LOCATION/immich-backup.env -source $SCRIPT_ABS_LOCATION/../logger.sh +source "$SCRIPT_ABS_LOCATION/immich-backup.env" +source "$SCRIPT_ABS_LOCATION/../logger.sh" # Container Names -APP_CONTAINER="immich_server" DB_CONTAINER="immich_postgres" BACKUP_CONTAINER="duplicati" @@ -13,43 +12,33 @@ BACKUP_CONTAINER="duplicati" DB_USER="postgres" SOURCE_DIR="/mnt/data/immich" -BACKUP_DESTINATION="$BACKUP_DESTINATION" -BACKUP_ENCR_PASSPHRASE="$BACKUP_ENCR_PASSPHRASE" - -# Cloud Storage Authentication -SFTP_USERNAME="$SFTP_USERNAME" -SFTP_PASSWORD="$SFTP_PASSWORD" -SFTP_FINGERPRINT="$SFTP_FINGERPRINT" - -# Log file -LOG_FILE="$SCRIPT_ABS_LOCATION/immich-backup.log" # Dump Database log "Dumping immich postgresql database..." DB_TMP_BAK_NAME="postgres_$(date +"%Y%m%d").bak" -docker exec -t $DB_CONTAINER pg_dumpall \ +docker exec -t "$DB_CONTAINER" pg_dumpall \ --clean \ --if-exists \ - --username=postgres \ - --file=/var/lib/postgresql/data/$DB_TMP_BAK_NAME || { log "Error: Failed to dump the immich database."; exit 1; } + --username="$DB_USER" \ + --file="/var/lib/postgresql/data/$DB_TMP_BAK_NAME" || { log "Error: Failed to dump the immich database."; exit 1; } # Backup all files to target destination log "Backing up immich files and database..." -docker exec $BACKUP_CONTAINER duplicati-cli backup ssh://$BACKUP_DESTINATION \ - $SOURCE_DIR/data/library \ - $SOURCE_DIR/data/upload \ - $SOURCE_DIR/data/profile \ - $SOURCE_DIR/postgres/$DB_TMP_BAK_NAME \ +docker exec "$BACKUP_CONTAINER" duplicati-cli backup "ssh://$BACKUP_DESTINATION" \ + "$SOURCE_DIR/data/library" \ + "$SOURCE_DIR/data/upload" \ + "$SOURCE_DIR/data/profile" \ + "$SOURCE_DIR/postgres/$DB_TMP_BAK_NAME" \ --backup-name="immich backup" \ --keep-versions=7 \ - --auth-username=$SFTP_USERNAME \ - --auth-password=$SFTP_PASSWORD \ + --auth-username="$SFTP_USERNAME" \ + --auth-password="$SFTP_PASSWORD" \ --passphrase="$BACKUP_ENCR_PASSPHRASE" \ --ssh-fingerprint="$SFTP_FINGERPRINT" \ --prefix="immich" || { log "Error: Failed to backup immich files and database."; exit 1; } # Delete temporary backup files log "Deleting temporary backup files..." -docker exec $DB_CONTAINER rm /var/lib/postgresql/data/$DB_TMP_BAK_NAME || { log "Error: Failed to delete temporary backup files."; exit 1; } +docker exec "$DB_CONTAINER" rm "/var/lib/postgresql/data/$DB_TMP_BAK_NAME" || { log "Error: Failed to delete temporary backup files."; exit 1; } log "immich backup completed successfully." diff --git a/nextcloud/nextcloud-backup.sh b/nextcloud/nextcloud-backup.sh index 39cafde..02704c7 100755 --- a/nextcloud/nextcloud-backup.sh +++ b/nextcloud/nextcloud-backup.sh @@ -1,8 +1,8 @@ #!/bin/bash SCRIPT_ABS_LOCATION=$(realpath "$(dirname "${0}")") -source $SCRIPT_ABS_LOCATION/nextcloud-backup.env -source $SCRIPT_ABS_LOCATION/../logger.sh +source "$SCRIPT_ABS_LOCATION/nextcloud-backup.env" +source "$SCRIPT_ABS_LOCATION/../logger.sh" # Container Names APP_CONTAINER="nextcloud-app" @@ -11,57 +11,46 @@ BACKUP_CONTAINER="duplicati" # Database Settings DB_USER="nextcloud" -DB_PASSWORD="$DB_PASSWORD" SOURCE_DIR="/mnt/data/nextcloud" -BACKUP_DESTINATION="$BACKUP_DESTINATION" -BACKUP_ENCR_PASSPHRASE="$BACKUP_ENCR_PASSPHRASE" - -# Cloud Storage Authentication -SFTP_USERNAME="$SFTP_USERNAME" -SFTP_PASSWORD="$SFTP_PASSWORD" -SFTP_FINGERPRINT="$SFTP_FINGERPRINT" - -# Log file -LOG_FILE="$SCRIPT_ABS_LOCATION/nextcloud-backup.log" # Put Nextcloud in Maintenance Mode log "Putting Nextcloud in maintenance mode..." -docker exec -u www-data $APP_CONTAINER php occ maintenance:mode --on || { log "Error: Failed to put Nextcloud in maintenance mode."; exit 1; } +docker exec -u www-data "$APP_CONTAINER" php occ maintenance:mode --on || { log "Error: Failed to put Nextcloud in maintenance mode."; exit 1; } # Dump Database log "Dumping Nextcloud database..." DB_TMP_BAK_NAME="nextcloud-db_$(date +"%Y%m%d").bak" -docker exec $DB_CONTAINER /usr/bin/mariadb-dump \ +docker exec "$DB_CONTAINER" /usr/bin/mariadb-dump \ --single-transaction \ -h localhost \ - -u $DB_USER \ + -u "$DB_USER" \ -p"$DB_PASSWORD" \ - nextcloud > $SOURCE_DIR/$DB_TMP_BAK_NAME || { log "Error: Failed to dump the Nextcloud database."; exit 1; } + nextcloud > "$SOURCE_DIR/$DB_TMP_BAK_NAME" || { log "Error: Failed to dump the Nextcloud database."; exit 1; } # Backup all files to target destination log "Backing up Nextcloud files and database..." -docker exec $BACKUP_CONTAINER \ +docker exec "$BACKUP_CONTAINER" \ duplicati-cli backup \ - ssh://$BACKUP_DESTINATION \ + "ssh://$BACKUP_DESTINATION" \ "$SOURCE_DIR/html/data" \ "$SOURCE_DIR/html/config" \ "$SOURCE_DIR/html/themes" \ "$SOURCE_DIR/$DB_TMP_BAK_NAME" \ --backup-name="nextcloud backup" \ --keep-versions=7 \ - --auth-username=$SFTP_USERNAME \ - --auth-password=$SFTP_PASSWORD \ - --passphrase=$BACKUP_ENCR_PASSPHRASE \ + --auth-username="$SFTP_USERNAME" \ + --auth-password="$SFTP_PASSWORD" \ + --passphrase="$BACKUP_ENCR_PASSPHRASE" \ --ssh-fingerprint="$SFTP_FINGERPRINT" \ --prefix="nextcloud" || { log "Error: Failed to backup Nextcloud files and database."; exit 1; } # Turn off Maintenance Mode log "Turning off Nextcloud maintenance mode..." -docker exec -u www-data $APP_CONTAINER php occ maintenance:mode --off || { log "Error: Failed to turn off Nextcloud maintenance mode."; exit 1; } +docker exec -u www-data "$APP_CONTAINER" php occ maintenance:mode --off || { log "Error: Failed to turn off Nextcloud maintenance mode."; exit 1; } # Delete temporary backup files log "Deleting temporary backup files..." -rm $SOURCE_DIR/$DB_TMP_BAK_NAME || { log "Error: Failed to delete temporary databse file"; exit 1; } +rm "$SOURCE_DIR/$DB_TMP_BAK_NAME" || { log "Error: Failed to delete temporary databse file"; exit 1; } log "Nextcloud backup completed successfully." diff --git a/portainer/portainer-backup.sh b/portainer/portainer-backup.sh index 0441641..f6d08ca 100755 --- a/portainer/portainer-backup.sh +++ b/portainer/portainer-backup.sh @@ -1,45 +1,35 @@ #!/bin/bash SCRIPT_ABS_LOCATION=$(realpath "$(dirname "${0}")") -source $SCRIPT_ABS_LOCATION/portainer-backup.env -source $SCRIPT_ABS_LOCATION/../logger.sh +source "$SCRIPT_ABS_LOCATION/portainer-backup.env" +source "$SCRIPT_ABS_LOCATION/../logger.sh" # Container Names APP_CONTAINER="portainer" BACKUP_CONTAINER="duplicati" SOURCE_DIR="/volumes/portainer" -BACKUP_DESTINATION="$BACKUP_DESTINATION" -BACKUP_ENCR_PASSPHRASE="$BACKUP_ENCR_PASSPHRASE" - -# Cloud Storage Authentication -SFTP_USERNAME="$SFTP_USERNAME" -SFTP_PASSWORD="$SFTP_PASSWORD" -SFTP_FINGERPRINT="$SFTP_FINGERPRINT" - -# Log file -LOG_FILE="$SCRIPT_ABS_LOCATION/portainer-backup.log" # Stop portainer container log "Stopping portainer container..." -docker stop $APP_CONTAINER || { log "Error: Failed to stop portainer."; exit 1; } +docker stop "$APP_CONTAINER" || { log "Error: Failed to stop portainer."; exit 1; } # Backup all files to target destination log "Backing up portainer files (including the SQLite database)..." -docker exec $BACKUP_CONTAINER \ +docker exec "$BACKUP_CONTAINER" \ duplicati-cli backup \ - ssh://$BACKUP_DESTINATION \ - $SOURCE_DIR \ + "ssh://$BACKUP_DESTINATION" \ + "$SOURCE_DIR" \ --backup-name="portainer backup" \ --keep-versions=7 \ - --auth-username=$SFTP_USERNAME \ - --auth-password=$SFTP_PASSWORD \ - --passphrase=$BACKUP_ENCR_PASSPHRASE \ + --auth-username="$SFTP_USERNAME" \ + --auth-password="$SFTP_PASSWORD" \ + --passphrase="$BACKUP_ENCR_PASSPHRASE" \ --ssh-fingerprint="$SFTP_FINGERPRINT" \ --prefix="portainer" || { log "Error: Failed to backup portainer files and database."; exit 1; } # Turn off Maintenance Mode log "Starting portainer container..." -docker start $APP_CONTAINER || { log "Error: Failed to start portainer container."; exit 1; } +docker start "$APP_CONTAINER" || { log "Error: Failed to start portainer container."; exit 1; } log "portainer backup completed successfully." diff --git a/vaultwarden/vaultwarden-backup.sh b/vaultwarden/vaultwarden-backup.sh index 4e2df9f..dc5c4cb 100755 --- a/vaultwarden/vaultwarden-backup.sh +++ b/vaultwarden/vaultwarden-backup.sh @@ -1,45 +1,34 @@ #!/bin/bash SCRIPT_ABS_LOCATION=$(realpath "$(dirname "${0}")") -source $SCRIPT_ABS_LOCATION/vaultwarden-backup.env -source $SCRIPT_ABS_LOCATION/../logger.sh +source "$SCRIPT_ABS_LOCATION/vaultwarden-backup.env" +source "$SCRIPT_ABS_LOCATION/../logger.sh" # Container Names -CONTAINER="vaultwarden" BACKUP_CONTAINER="duplicati" SOURCE_DIR="/mnt/data/vaultwarden" -BACKUP_DESTINATION="$BACKUP_DESTINATION" -BACKUP_ENCR_PASSPHRASE="$BACKUP_ENCR_PASSPHRASE" - -# Cloud Storage Authentication -SFTP_USERNAME="$SFTP_USERNAME" -SFTP_PASSWORD="$SFTP_PASSWORD" -SFTP_FINGERPRINT="$SFTP_FINGERPRINT" - -# Log file -LOG_FILE="$SCRIPT_ABS_LOCATION/vaultwarden-backup.log" # Dump Database log "Dumping vaultwarden database..." DB_TMP_BAK_NAME=vaultwarden-db_$(date +"%Y%m%d").sqlite3 -sqlite3 $SOURCE_DIR/db.sqlite3 ".backup '$SOURCE_DIR/$DB_TMP_BAK_NAME'" || { log "Error: Failed to dump the Nextcloud database."; exit 1; } +sqlite3 "$SOURCE_DIR/db.sqlite3 .backup '$SOURCE_DIR/$DB_TMP_BAK_NAME'" || { log "Error: Failed to dump the Nextcloud database."; exit 1; } # Backup all files to target destination log "Backing up vaultwarden files and database..." -docker exec $BACKUP_CONTAINER duplicati-cli backup \ - ssh://$BACKUP_DESTINATION \ - $SOURCE_DIR \ +docker exec "$BACKUP_CONTAINER" duplicati-cli backup \ + "ssh://$BACKUP_DESTINATION" \ + "$SOURCE_DIR" \ --backup-name="vaultwarden backup" \ --keep-versions=7 \ - --auth-username=$SFTP_USERNAME \ - --auth-password=$SFTP_PASSWORD \ + --auth-username="$SFTP_USERNAME" \ + --auth-password="$SFTP_PASSWORD" \ --passphrase="$BACKUP_ENCR_PASSPHRASE" \ --ssh-fingerprint="$SFTP_FINGERPRINT" \ --prefix="vaultwarden" || { log "Error: Failed to backup vaultwarden files and database."; exit 1; } # Delete temporary backup files log "Deleting temporary backup files..." -rm $SOURCE_DIR/$DB_TMP_BAK_NAME || { log "Error: Failed to delete temporary backup files."; exit 1; } +rm "$SOURCE_DIR/$DB_TMP_BAK_NAME" || { log "Error: Failed to delete temporary backup files."; exit 1; } log "vaultwarden backup completed successfully."