From 61294c9d2c70a3f7aa7ab1d19308b2a2373d3927 Mon Sep 17 00:00:00 2001 From: ge Date: Sun, 9 Oct 2022 00:51:08 +0300 Subject: [PATCH] Various improvements --- ...ing-backup.ru.1.rst => boring_backup.ru.1.rst} | 3 +-- src/boring_backup | 2 +- src/lib/common.sh | 15 ++++++++------- src/lib/handlers/sources/mysqldump.sh | 2 +- src/lib/handlers/sources/pg_dump.sh | 2 +- src/lib/handlers/targets/cp.sh | 2 +- src/lib/handlers/targets/s3cmd.sh | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) rename docs/manpages/{boring-backup.ru.1.rst => boring_backup.ru.1.rst} (99%) diff --git a/docs/manpages/boring-backup.ru.1.rst b/docs/manpages/boring_backup.ru.1.rst similarity index 99% rename from docs/manpages/boring-backup.ru.1.rst rename to docs/manpages/boring_backup.ru.1.rst index b651956..25e4152 100644 --- a/docs/manpages/boring-backup.ru.1.rst +++ b/docs/manpages/boring_backup.ru.1.rst @@ -602,7 +602,6 @@ s3 sources=(.) # just pass validation targets=(.) today="$(date +%d_%b_%Y)" - s3cmd_config=~/.s3cfg prepare() { systemctl stop gitea.service sleep 5 @@ -610,7 +609,7 @@ s3 backup() { log -p "Dumping Gitea" su -c "/usr/local/bin/gitea dump -c /etc/gitea/app.ini \ - -f /home/git/.cache/gitea_dump.zip" - git 2>> "$__log_file" + -f /home/git/.cache/gitea_dump.zip" - git 2>> "$log_file" backups+=(/home/git/.cache/gitea_dump.zip) tgt_s3cmd s3://mybucket/backups/gitea-$today } diff --git a/src/boring_backup b/src/boring_backup index 8457707..a7587dc 100755 --- a/src/boring_backup +++ b/src/boring_backup @@ -282,7 +282,7 @@ for script in "${__args[@]}"; do done echo -e "\nBackup [Done]" -log -V "Backup finished successsfully" +log -V "Backup finished successfully" # Remove PID file rm "$pid_file" diff --git a/src/lib/common.sh b/src/lib/common.sh index 95833ca..3c57cca 100644 --- a/src/lib/common.sh +++ b/src/lib/common.sh @@ -56,7 +56,7 @@ log() { while read -r line; do if [ -n "$line" ]; then if [ -n "$use_syslog" ]; then - logger --id="$$" --tag boring_backup "$line" + logger --id="$$" --tag boring_backup -- "$line" else # shellcheck disable=SC2154 printf '[%s] %s\n' \ @@ -172,7 +172,8 @@ compress_file() { # # Usage: compress_file FILE - local compressed + local uncompressed="$1" + local compressed= # Select compression utility and set filename extension. if [ -n "$compression" ]; then @@ -185,18 +186,18 @@ compress_file() { # Compress file if [ -n "$cmpr_cmd" ]; then log -V "Compressing file $1 by ${cmpr_cmd%% *} ..." - $cmpr_cmd "$1" 2>> "$log_file" - compressed="${1}${cmpr_ext}" + $cmpr_cmd "$uncompressed" |& log + compressed="${uncompressed}${cmpr_ext}" # Remove original file. if [ -f "$compressed" ]; then - if [ -f "$1" ]; then + if [ -f "$uncompressed" ]; then log "Remove uncompressed file $1" - rm -- "$1" + rm -- "$uncompressed" fi fi else - compressed="$1" + compressed="$uncompressed" fi echo "$compressed" diff --git a/src/lib/handlers/sources/mysqldump.sh b/src/lib/handlers/sources/mysqldump.sh index 998a5dd..3836814 100644 --- a/src/lib/handlers/sources/mysqldump.sh +++ b/src/lib/handlers/sources/mysqldump.sh @@ -63,7 +63,7 @@ src_mysqldump() { log "Run command: $*" # shellcheck disable=SC2154 - "$@" > "$sqldump" |& log + "$@" > "$sqldump" 2>> "$log_file" sqldump="$(compress_file "$sqldump")" # Compress file backups+=("$sqldump") # Append path to 'backups' array log "Dump saved as: $sqldump" diff --git a/src/lib/handlers/sources/pg_dump.sh b/src/lib/handlers/sources/pg_dump.sh index 90e6199..d9be9b3 100644 --- a/src/lib/handlers/sources/pg_dump.sh +++ b/src/lib/handlers/sources/pg_dump.sh @@ -64,7 +64,7 @@ src_pg_dump() { log "Run command: $*" # shellcheck disable=SC2154 - "$@" > "$sqldump" |& log + "$@" > "$sqldump" 2>> "$log_file" sqldump="$(compress_file "$sqldump")" # Compress file backups+=("$sqldump") log "Dump file: $sqldump" diff --git a/src/lib/handlers/targets/cp.sh b/src/lib/handlers/targets/cp.sh index bcea3d1..98484bd 100644 --- a/src/lib/handlers/targets/cp.sh +++ b/src/lib/handlers/targets/cp.sh @@ -59,6 +59,6 @@ tgt_cp() { set -- cp --archive "$backup" "$dst_path" log "Run command: $*" - "$@" |& log + "$@" 2>> "$log_file" done } diff --git a/src/lib/handlers/targets/s3cmd.sh b/src/lib/handlers/targets/s3cmd.sh index dccb1ab..6787fb7 100644 --- a/src/lib/handlers/targets/s3cmd.sh +++ b/src/lib/handlers/targets/s3cmd.sh @@ -71,5 +71,5 @@ tgt_s3cmd() { # Upload backups # shellcheck disable=SC2154 #"$@" 2>> "$log_file" - "$@" |& log + "$@" 2>> "$log_file" }