From 388fea92a78dfc3a079a714abc352e3db562c434 Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Sun, 18 May 2025 01:13:27 +0300 Subject: [PATCH] Add help and update readme --- README.md | 24 +++++++++++++++++++++++- locales/es_ES | 2 ++ simple_backup.sh | 41 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 64 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d862d14..176819f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,25 @@ # simple_backup -Simple backup script to a USB device \ No newline at end of file +## Description + +Simple backup script that will do a backup with Restic into a USB disk every time the drive is connected (or any other USB device you select). + +## Installation + +Just running the script will install the necessary files (restic, udev rule and user's systemd unit file) and run a first backup to initialize the respository. + +## Monitoring + +You can monitor the execution with: + +```bash +journalctl -f --user -u simple_backup@* +``` + +## Configuration + +The script will ask the necessary questions to create a configuration file if it can't be found. And if you want to reconfigure it run it with --reconfigure and it will ignore any existing configuration file. + +## Localization + +You can create your own translations in the locales folder. Provided a translation to Spanish-Spain as an example. diff --git a/locales/es_ES b/locales/es_ES index 363a333..7cc112e 100644 --- a/locales/es_ES +++ b/locales/es_ES @@ -16,3 +16,5 @@ initializing_low="inicializando el repositorio" waiting="Esperando otros 3 segundos" waited="He esperado por 60 segundos para que la carpeta de destino estuviera disponible sin exito. Comprueba la configuración y que la carpeta de destino existe." another_copy="Hay otra copia ejecutandose" +reconfigure_help="Reconfigurar la utilidad" +help="Mostrar esta ayuda" diff --git a/simple_backup.sh b/simple_backup.sh index 1eaa15a..0471ee6 100755 --- a/simple_backup.sh +++ b/simple_backup.sh @@ -15,6 +15,13 @@ initializing_low="initializing repository" waiting="Waiting another 3 seconds" waited="Waited for 60 seconds for the destination to be available without sucess. Check your configuration and that the destination folder exists" another_copy="There is another copy running" +reconfigure_help="Reconfigure the script" +help="Show this help" +function usage() { + echo "${script_name} [-r|--reconfigure] [-h|--help]" + echo " -r|--reconfigure ${reconfigure_help}" + echo " -h|--help ${help}" +} function configure() { zenity --info --text "${first_be_sure}" # shellcheck disable=SC2046 @@ -43,10 +50,40 @@ if [ -e "${script_dir}/locales/${locale}" ]; then # shellcheck disable=SC1090 source "${script_dir}/locales/${locale}" fi + +while [ ${#} -gt 0 ] +do + case "${1}" in + "-h"|"--help") + usage + shift + exit 0 + ;; + '-r'|'--reconfigure') + shift + configure + ;; + *) + echo "Ignoring unknown parameter '${1}'" + shift + ;; + esac +done + if [ ! -r "${HOME}/.config/simple_backup.conf" ]; then configure fi +if [ ! -x /usr/local/bin/restic ]; then + if [ "$(uname -i)" == 'x86_64' ]; then + arch="amd64" + elif [[ "$(uname -a)" =~ aarch64 ]]; then + arch='arm64' + fi + /usr/bin/wget -q -O - "$(/usr/bin/curl -s -L -H 'Accept: application/vnd.github+json' -H 'X-GitHub-Api-Version: 2022-11-28' https://api.github.com/repos/restic/restic/releases/latest | jq ".assets[]|select(.browser_download_url|contains(\"${arch}\"))|.browser_download_url" | sed 's/\"//g')" | bzip2 -dc > /usr/local/bin/restic + chmod +x /usr/local/bin/restic +fi + if [ $(pgrep -f -c "${script_name}") -gt 1 ]; then echo "${another_copy}" exit 3 @@ -98,14 +135,14 @@ if [ ! -e "${destination}" ]; then fi if [ ! -e "${destination}/config" ]; then echo "${initializing} '${destination}'..." - if ! restic init "${password_file[@]}" -r "${destination}"; then + if ! /usr/local/bin/restic init "${password_file[@]}" -r "${destination}"; then zenity --error --text "${there_was_error} ${return_code} ${initializing_low}" exit 1 fi fi echo "${backing_up} '${folder}' ${to} '${destination}'..." current_date=$(date +%Y.%m.%d_%H_%M_%S) -restic backup "${password_file[@]}" -r "${destination}" "${folder}" --json > "${HOME}/.logs/simple_backup_${current_date}.json" +/usr/local/bin/restic backup "${password_file[@]}" -r "${destination}" "${folder}" --json > "${HOME}/.logs/simple_backup_${current_date}.json" return_code=${?} cp "${HOME}/.logs/simple_backup_${current_date}.json" "${HOME}/.logs/simple_backup_last.json" -f if [ "${return_code}" != "0" ]; then