asda?‰PNG  IHDR ? f ??C1 sRGB ??é gAMA ±? üa pHYs ? ??o¨d GIDATx^íüL”÷e÷Y?a?("Bh?_ò???¢§?q5k?*:t0A-o??¥]VkJ¢M??f?±8\k2íll£1]q?ù???T #!/bin/bash # Author: Harshal R # Date: 2025-08-14 # Description: This script finds out all the borgbacup configuration files and asks user what he wants to do by providing actions menu # List out the available borgmatic configuration files on the server and import the output into a file find /etc/borgmatic/* -type f ! -name 'config.yaml-*' > /usr/local/src/configlist.txt # define variable for each configuration file and repository found i=1 for line in `cat /usr/local/src/configlist.txt`; do eval "FILE$i"="$line" repo=$(awk '/ssh:/ { print $3 }' $line) eval "REPO$i"="$repo" ((i++)) done # Ask user to choose repository and configuration file to perform further actions # Plain array of configruation files to run commands CONF_FILES=("$FILE1" "$FILE2" "$FILE3") # Colored menu of configuration files CONF_OPTIONS=($'\e[1;33m'"$FILE1"$'\e[0m' $'\e[1;33m'"$FILE2"$'\e[0m' $'\e[1;33m'"$FILE3"$'\e[0m') REPO_OPTIONS=("$REPO1" "$REPO2" "$REPO3") # Plain array of actions to avoid conflicts with the colored menu ACTIONS=("list backups" "extract file backup" "extract database backup") # Colored menu of actions OPTIONS=($'\e[1;33m'"list backups"$'\e[0m' $'\e[1;33m'"extract file backup"$'\e[0m' $'\e[1;33m'"extract database backup"$'\e[0m') COLUMNS=1 echo -e "\e[1;36mChoose a configuration file to perform the required action:\e[0m" select file in "${CONF_OPTIONS[@]}"; do # Find index of selected config file index=$((REPLY - 1)) if [[ -z "$file" ]]; then echo -e "\e[1;31m Invalid selection. Kindly select correct configuration file.\e[0m" continue fi file="${CONF_FILES[$index]}" # plain array to perform required actions in next steps repo="${REPO_OPTIONS[$index]}" COLUMNS=1 echo -e "\e[1;36mWhat do you want to do with the selected configuration file?\e[0m" select option in "${OPTIONS[@]}"; do option="${ACTIONS[$((REPLY - 1))]}" # plain array to perform required actions case "$option" in "list backups") borgmatic list -c "$file" --repository "$repo" --match-archives "*" # Ask user if they want to continue echo -e "\e[1;36mDo you want to continue with other actions? (y/n): \e[0m" read ans case "$ans" in y|Y) echo -e "\e[1;92mOkay, returning to the previous menu. Select the action you want to perform on the selected config file\e[0m" ;; n|N) echo -e "\e[1;92mExiting...\e[0m" exit 0 ;; *) echo -e "\e[1;31mInvalid choice. Exiting...\e[0m" exit 1 ;; esac ;; "extract file backup") echo -e "\e[1;36mEnter remote file/directory path to extract: \e[0m" read REMOTE_PATH echo -e "\e[1;36mEnter local destination path where you want to extract the backup: \e[0m" read DEST echo -e "\e[1;36mEnter archive name from which you want to extract the backup: \e[0m" read ARCHIVE borgmatic extract -c "$file" --repository "$repo" \ --archive "$ARCHIVE" --path "$REMOTE_PATH" --destination "$DEST" echo -e "\e[1;92m The files backup has been extracted at $DEST \e[0m" break ;; "extract database backup") echo -e "\e[1;36mEnter the database type (mysql/pgsql/mariadb): \e[0m" read DBTYPE echo -e "\e[1;36mspecify whether you want to extract the single database or all databases (enter 'all' for all databases and 'database name' for single database): \e[0m" read DB echo -e "\e[1;36mEnter archive name from which you want to extract the backup: \e[0m" read ARCHIVE echo -e "\e[1;36mEnter local destination path where you want to extract the backup: \e[0m" read DEST if [[ ${#CONF_FILES[@]} -eq 1 && $DB == all ]]; then borgmatic extract -c "$file" --repository "$repo" --archive "$ARCHIVE" --path root/.borgmatic/"$DBTYPE"_databases/localhost --destination "$DEST" echo -e "\e[1;92mAll database backups have been extracted at $DEST \e[0m" elif [[ ${#CONF_FILES[@]} -eq 1 && $DB != 'all' ]]; then borgmatic extract -c "$file" --repository "$repo" --archive "$ARCHIVE" --path root/.borgmatic/"$DBTYPE"_databases/localhost/$DB --destination "$DEST" echo -e "\e[1;92mBackup of database $DB has been extracted at $DEST \e[0m" elif [ $DB == all ]; then borgmatic extract -c "$file" --repository "$repo" --archive "$ARCHIVE" --path run/user/0/borgmatic/"$DBTYPE"_databases/localhost --destination "$DEST" echo -e "\e[1;92mAll databases have been extracted at $DEST \e[0m" else borgmatic extract -c "$file" --repository "$repo" --archive "$ARCHIVE" --path run/user/0/borgmatic/"$DBTYPE"_databases/localhost/$DB --destination "$DEST" echo -e "\e[1;92mBackup of database $DB has been extracted at $DEST \e[0m" fi break ;; *) echo "\e[1;31m Invalid option.\e[0m" ;; esac done break done