]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Adding PostgreSQL backup.
authorFrank Brehm <frank@brehm-online.com>
Tue, 20 Apr 2021 12:55:18 +0000 (14:55 +0200)
committerFrank Brehm <frank@brehm-online.com>
Tue, 20 Apr 2021 12:55:18 +0000 (14:55 +0200)
bin/manual-backup

index 9952d8a740dbc8c4cb3c6567c44875a74b5a9a13..8ac05d171050ebe67f3ead03602d3c9e189400a7 100755 (executable)
@@ -306,7 +306,11 @@ do_mysql_backup(){
         cmd+=" --verbose"
     fi
     cmd+=" --log-error=\"${errorlog}\""
-    cmd+=" | gzip -9 > \"${dumpfile}\""
+    cmd+=" | gzip -9"
+    if [[ "${VERBOSE}" == "y" ]] ; then
+        cmd+=" --verbose"
+    fi
+    cmd+=" > \"${dumpfile}\""
     if [[ "${SIMULATE}" == "y" ]] ; then
         info "Executing: ${cmd}"
         return
@@ -329,6 +333,57 @@ do_mysql_backup(){
 
 }
 
+#------------------------------------------------------------------------------
+do_postgres_backup() {
+
+    empty_line
+    info "Dumping PostgreSQL Databases ..."
+
+    debug "Dumping PostgreSQL globals ..."
+    local dumpfile="${BACKUP_DIR}/postgres.@globals.dump.sql.gz"
+    local cmd="su - postgres -c \"pg_dumpall"
+    if [[ "${VERBOSE}" == "y" ]] ; then
+        cmd+=" --verbose"
+    fi
+    cmd+=" --globals-only --clean --encoding=utf-8 --disable-triggers --if-exists\""
+    cmd+=" | gzip -9"
+    if [[ "${VERBOSE}" == "y" ]] ; then
+        cmd+=" --verbose"
+    fi
+    cmd+=" > \"${dumpfile}\""
+    if [[ "${SIMULATE}" == "y" ]] ; then
+        info "Executing: ${cmd}"
+    else
+        debug "Executing: ${cmd}"
+        eval ${cmd}
+    fi
+
+    local db=
+
+    for db in $( su - postgres -c "psql -X -x --list --tuples-only --no-align" | \
+            grep -i '^name|' | awk -F'|' '{print $2}' ) ; do
+        debug "Dumping PostgreSQL database '${CYAN}${db}${NORMAL}' ..."
+        dumpfile="${BACKUP_DIR}/postgres.${db}.dump.sql.gz"
+        cmd="su - postgres -c \"pg_dump"
+        if [[ "${VERBOSE}" == "y" ]] ; then
+            cmd+=" --verbose"
+        fi
+        cmd+=" --blobs --clean --create --encoding=utf-8 --disable-triggers --if-exists '${db}'\""
+        cmd+=" | gzip -9"
+        if [[ "${VERBOSE}" == "y" ]] ; then
+            cmd+=" --verbose"
+        fi
+        cmd+=" > \"${dumpfile}\""
+        if [[ "${SIMULATE}" == "y" ]] ; then
+            info "Executing: ${cmd}"
+            continue
+        fi
+        debug "Executing: ${cmd}"
+        eval ${cmd}
+    done
+
+}
+
 #------------------------------------------------------------------------------
 create_checksums() {
 
@@ -451,6 +506,9 @@ main() {
     if [[ "${DO_MYSQL}" == "y" ]] ; then
         do_mysql_backup
     fi
+    if [[ "${DO_POSTGRES}" == "y" ]] ; then
+        do_postgres_backup
+    fi
     create_checksums
     clean_old_backups
     sync_to_remote