Current location

narf Source control manager Git

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Mehani <shtrom@ssji.net>2021-09-24 02:27:32 +0200
committerOlivier Mehani <shtrom@ssji.net>2021-09-24 02:27:32 +0200
commitc32ced5c94fe62e56c4640d3f57211d1806792e6 (patch)
tree79569d78b91725d0d846cd5b98d115a1a78eddef
parent24680ef92b11b5595cee2e374cdca3788f180b4e (diff)
[openbsd/backup] Only overwrite DB dumps if successful
Signed-off-by: Olivier Mehani <shtrom@ssji.net>
-rwxr-xr-xopenbsd/backup.sh19
1 files changed, 13 insertions, 6 deletions
diff --git a/openbsd/backup.sh b/openbsd/backup.sh
index 35bd795..3e8051c 100755
--- a/openbsd/backup.sh
+++ b/openbsd/backup.sh
@@ -45,10 +45,15 @@ fi
echo -n "Dumping databases:"
if [ ! -z "$MYSQLDUMPDIR" ]; then
MYSQLDUMP="${MYSQLDUMPDIR}mysql.dump.sql"
- echo -n " mysql (${MYSQLDUMP})"
+ TMP_MYSQLDUMP=$(mktemp ${MYSQLDUMP}.XXXXXXXX)
+ echo -n " mysql (${TMP_MYSQLDUMP})"
# GRANT SELECT, SHOW VIEW, TRIGGER, LOCK TABLES ON *.* TO 'dumper'@'localhost';
- ${MYSQLBINPATH}mysqldump --all-databases --comments --dump-date -u ${MYSQLUSER} > ${MYSQLDUMP}
- mysqldump-grants -u ${MYSQLUSER} >> ${MYSQLDUMP}
+ (
+ ${MYSQLBINPATH}mysqldump --all-databases --comments --dump-date -u ${MYSQLUSER} \
+ && mysqldump-grants -u ${MYSQLUSER}
+ ) > ${TMP_MYSQLDUMP} \
+ && mv ${TMP_MYSQLDUMP} ${MYSQLDUMP}
+ rm -f ${TMP_MYSQLDUMP}
fi
if [ ! -z "$LDAPDUMPDIR" ]; then
@@ -57,9 +62,11 @@ if [ ! -z "$LDAPDUMPDIR" ]; then
${LDAPPASS}
EOF
LDAPDUMP="${LDAPDUMPDIR}ldap.dump.ldiff"
- echo -n " ldap (${LDAPDUMP})"
- TERM=vt100 ${LDAPBINPATH}ldapvi --noninteractive --quiet --noquestions --out --host localhost -D "${LDAPUSER}" -y "${LDAPPASSFILE}" > ${LDAPDUMP}
- rm -f ${LDAPPASSFILE}
+ TMP_LDAPDUMP="$(mktemp ${LDAPDUMPDIR}.XXXXXXXX)"
+ echo -n " ldap (${TMP_LDAPDUMP})"
+ TERM=vt100 ${LDAPBINPATH}ldapvi --noninteractive --quiet --noquestions --out --host localhost -D "${LDAPUSER}" -y "${LDAPPASSFILE}" > ${TMP_LDAPDUMP} \
+ && mv ${TMP_LDAPDUMP} ${LDAPDUMP}
+ rm -f ${LDAPPASSFILE} ${TMP_LDAPDUMP}
fi
echo "."