git.lirion.de

Of git, get, and gud

aboutsummaryrefslogtreecommitdiffstats
path: root/bin/sqlbackup
diff options
context:
space:
mode:
Diffstat (limited to 'bin/sqlbackup')
-rwxr-xr-xbin/sqlbackup16
1 files changed, 10 insertions, 6 deletions
diff --git a/bin/sqlbackup b/bin/sqlbackup
index 552198f..69bbfbc 100755
--- a/bin/sqlbackup
+++ b/bin/sqlbackup
@@ -133,6 +133,9 @@ WAT="\033[666D[\033[0;33mWARN\033[0m]\033[u\033[K"
mkdir -p "$BDIR"&&chmod 0700 "$BDIR"||exit 188
BLOG="$BDIR""/sqlbackup.log"
touch "$BLOG"||exit 189
+# check normal write exit explicitly before first write to ensure there is no
+# "backyard" file lock like stale mounts or whatever
+true >> "$BLOG"||exit 189
chmod 0600 "$BLOG"||exit 190
@@ -141,11 +144,11 @@ chmod 0600 "$BLOG"||exit 190
TIME="$(date +"%Y-%m-%dT%H:%M:%S%z")"
[ "$SCHANAUZE" -ne 1 ]&&printf "File timestamp: %s\n" "$TIME"
-printf "File timestamp: %s\n" "$TIME" > "$BLOG"
+printf "File timestamp: %s\n" "$TIME" >> "$BLOG"
# Flush prior to backups, do not purge.
[ "$SCHANAUZE" -ne 1 ]&&printf "\n[....] Flushing logs.\033[s..\033[0m"
[ ! -z "$LOGGER" ]&&[ "$LOGGER" -eq 1 ]&&mlogger info "flushing logs"
-mysql --user="$BUSER" --password="$(cat $PWFL)" -e "flush logs \\G"
+mysql --user="$BUSER" --password="$(cat $PWFL)" -e "flush logs \\G" 2>> "$BLOG"
if [ "$?" -ne 0 ];then
[ ! -z "$LOGGER" ]&&[ "$LOGGER" -eq 1 ]&&mlogger err "flushing logs failed, check $BLOG"
[ "$SCHANAUZE" -ne 1 ]&&printf "$NEE\n\n"
@@ -156,7 +159,7 @@ fi
exit 0
LOGPOS="$(mysql --user="$BUSER" --password="$(cat $PWFL)" -e "show master status \G"|grep Position|awk '{print $NF}')"
[ "$SCHANAUZE" -ne 1 ]&&printf "Log position: %s\n" "$LOGPOS"
-printf "Log position: %s\n" "$LOGPOS" > "$BLOG"
+printf "Log position: %s\n" "$LOGPOS" >> "$BLOG"
# Get latest non-relay binary log:
find "$DBFDIR" -maxdepth 1 -cmin 2 >/dev/null 2>&1
if [ "$?" -ne 0 ];then
@@ -187,9 +190,9 @@ for i in "${DBARR[@]}";do
sleep 0.1337
[ "$SCHANAUZE" -ne 1 ]&&printf ".. \033[u\033[K \033[1;30mdump running...\033[0m"
if ( [ "$i" == "mysql" ] || [ "$i" == "information_schema" ] || [ "$i" == "performance_schema" ] );then
- mysqldump "${ISAM_DUMPOPTS[@]}" -u "$BUSER" --password="$(cat "$PWFL")" --databases "$i" > "$BDIR/$i-$TIME.sql" 2> "$BLOG"
+ mysqldump "${ISAM_DUMPOPTS[@]}" -u "$BUSER" --password="$(cat "$PWFL")" --databases "$i" > "$BDIR/$i-$TIME.sql" 2>> "$BLOG"
else
- mysqldump "${INNO_DUMPOPTS[@]}" -u "$BUSER" --password="$(cat "$PWFL")" --databases "$i" > "$BDIR/$i-$TIME.sql" 2> "$BLOG"
+ mysqldump "${INNO_DUMPOPTS[@]}" -u "$BUSER" --password="$(cat "$PWFL")" --databases "$i" > "$BDIR/$i-$TIME.sql" 2>> "$BLOG"
fi
if [ "$?" -ne 0 ];then
[ ! -z "$LOGGER" ]&&[ "$LOGGER" -eq 1 ]&&mlogger err "backup of $i failed, check $BLOG"
@@ -209,7 +212,8 @@ for i in "${DBARR[@]}";do
echo -e "$OGE"
done
[ "$SCHANAUZE" -ne 1 ]&&printf "[....] Purging binary logs.\033[s..\033[0m"
-mysql --user="$BUSER" --password="$(cat $PWFL)" -e "purge binary logs to \"$BINLOGF\" \\G"
+[ ! -z "$LOGGER" ]&&[ "$LOGGER" -eq 1 ]&&mlogger info "Purging binary logs..."
+mysql --user="$BUSER" --password="$(cat $PWFL)" -e "purge binary logs to \"$BINLOGF\" \\G" 2>> "$BLOG"
if [ "$?" -ne 0 ];then
[ "$SCHANAUZE" -ne 1 ]&&echo -e "$NEE"
[ ! -z "$LOGGER" ]&&[ "$LOGGER" -eq 1 ]&&mlogger err "purging of binary logs failed, check $BLOG"